3

我在将本地开发环境升级到 php8 后阅读了这篇文章。

并在我的课堂上实现它,比如:

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

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

它返回错误。

语法错误,意外标记“<<”,需要“function”或“const”

在 php8 中这样做真正合适的是什么。我错过了什么吗?

4

1 回答 1

5

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

#[Attribute('foo')]

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

于 2020-11-28T03:14:15.873 回答