syntax error, finally block is not recognized

2019-08-09 17:51发布

Get syntax error, unexpected '{'. When I delete, finally block it works. that is a GET method of RESTful service.

Route::resource('braining/firmware', 'Braining\FirmwareController',
                    ['only' => ['index']]); 

Controller

<?php
namespace App\Http\Controllers\Braining;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class FirmwareController extends Controller
{
    public function index() {
        try {
        }
        catch(Exception $e) {
        }
        finally {
        }
    }
}

2条回答
唯我独甜
2楼-- · 2019-08-09 18:48

Upgrade PHP to version 5.5 and the problem will go away.

In PHP 5.5 and later, a finally block may also be specified after or instead of catch blocks. Code within the finally block will always be executed after the try and catch blocks, regardless of whether an exception has been thrown, and before normal execution resumes.

Source: http://php.net/manual/en/language.exceptions.php#language.exceptions.finally

查看更多
家丑人穷心不美
3楼-- · 2019-08-09 18:51

You must be using PHP 5.4 or lower which does not have the finally implemented yet. Either remove it or upgrade the PHP to 5.5

查看更多
登录 后发表回答