public function index() { $posts = (new-6ren">
gpt4 book ai didi

php - 语法错误,意外标记 "<<",期望 "function"或 "const"

转载 作者:行者123 更新时间:2023-12-05 02:47:19 25 4
gpt4 key购买 nike

我读了这个article将我的本地开发环境升级到 php8 之后。

并在我的类(class)中实现它,例如:

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

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

并返回错误。

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

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

最佳答案

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

#[Attribute('foo')]

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

关于php - 语法错误,意外标记 "<<",期望 "function"或 "const",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65045906/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com