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

syntax error, unexpected token "

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

I read this article after upgrading my local dev environment to php8.

And implement it in my class, like:

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

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

and it return error.

syntax error, unexpected token "<<", expecting "function" or "const"

What is really a proper of doing that in php8. Am i missing something?

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

Correct attribute syntax in PHP 8 is:

#[Attribute('foo')]

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