我在将本地开发环境升级到 php8 后阅读了这篇文章。
并在我的班级中实现它,例如:
<<Attribute('foo')>>
public function index()
{
$posts = (new Post)->get()->withMany('image');
return $this->app()->view('index', compact('posts'));
}
Run Code Online (Sandbox Code Playgroud)
它返回错误。
语法错误,意外标记“<<”,需要“function”或“const”
在 php8 中这样做的真正正确之处是什么?我错过了什么吗?
PHP 8 中正确的属性语法是:
#[Attribute('foo')]
Run Code Online (Sandbox Code Playgroud)
https://www.php.net/releases/8.0/en.php