Warm tip: This article is reproduced from serverfault.com, please click

php-语法错误,意外令牌“

(php - syntax error, unexpected token ")

发布于 2020-11-28 02:41:44

将本地开发环境升级到php8后,我阅读了本文

并在我的课程中实现它,例如:

<<Attribute('foo')>>
public function index()
{
    $posts = (new Post)->get()->withMany('image');

    return $this->app()->view('index', compact('posts'));
}

它返回错误。

语法错误,意外的标记“ <<”,应为“ function”或“ const”

在php8中真正做到这一点真正合适。我想念什么吗?

Questioner
Fil
Viewed
0
Konstantin Bogomolov 2020-11-28 11:14:15

PHP 8中正确的属性语法为:

#[Attribute('foo')]

https://www.php.net/releases/8.0/en.php