laravel 期待标识符 T_STRING
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38412165/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Expecting identifier T_STRING
提问by Polarize
Laravel seems to be throwing an error at line 3 use App\List;
but I can't seem to figure out the problem as I'm new to Laravel (perhaps it's a PHP version issue?).
Laravel 似乎在第 3 行抛出错误,use App\List;
但我似乎无法弄清楚问题,因为我是 Laravel 的新手(也许是 PHP 版本问题?)。
Error:
syntax error, unexpected 'List' (T_LIST), expecting identifier (T_STRING)
错误:
syntax error, unexpected 'List' (T_LIST), expecting identifier (T_STRING)
Here is my PageController
Class:
这是我的PageController
班级:
<?php
use App\List;
namespace App\Http\Controllers;
class PageController extends Controller
{
public function home(){
$lists = List::all();
return view('home', compact('lists'));
}
}
and here is App\List
这是 App\List
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class List extends Model
{
public function items(){
return $this->hasMany(ListItem::class);
}
}
回答by Grzegorz Gajda
You cannot name a class List
. See more: List of Reserved Words
你不能命名一个类List
。查看更多:保留字列表
回答by Alex Harris
You cannot name a class List
. I have had this issue, it is a reserved word.
你不能命名一个类List
。我遇到过这个问题,它是一个保留字。