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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:10:03  来源:igfitidea点击:

Expecting identifier T_STRING

phplaravel

提问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 PageControllerClass:

这是我的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。我遇到过这个问题,它是一个保留字