阵列意外启动[

时间:2014-01-27 16:26:45

标签: php arrays

我一直收到此错误

syntax error, unexpected '[' 

它位于以下代码段的第1行中:

Route.php

Route::get('api/test/{input}', [
    'before' => 'checkauth',
    "as"   => "test",
    "uses" => "TestController@show"
]);

出了什么问题?

2 个答案:

答案 0 :(得分:3)

更改数组表示法。

Route::get('api/test/{input}', array(
    'before' => 'checkauth',
    "as"   => "test",
    "uses" => "TestController@show"
));

答案 1 :(得分:0)

正如Michael Berkowski所说,使用[数组表示法需要PHP 5.4 +

来自Php array documentation

  

从PHP 5.4开始,您还可以使用短数组语法,它将array()替换为[]。

您应该使用array();表示法:

Route::get('api/test/{input}', array(
    'before' => 'checkauth',
    "as"   => "test",
    "uses" => "TestController@show"
));