Netbeans IDE (12.2):PHP 8.0 构造函数提升的语法错误

Netbeans IDE (12.2): Syntax error with PHP 8.0 constructor promotion

我正在处理 PHP 中的新 Attributes(a.k.a。“注释”),但我遇到了这个烦人的问题,Netbeans 12.2 无法识别我的有效 PHP 8.0 代码。我已经在我的本地机器上和这里测试过它:https://sandbox.onlinephpfunctions.com/.

虽然代码似乎编译得很好。其他 PHP 8.0 函数也在 IDE 中工作(...好吧,它是相同的二进制文件)。我可以以某种方式修复或忽略此错误吗?因为它将我的整个工作区标记为错误。

<?php

#[Routing('hello')]
class A {
    public function __construct() {}
}

#[Routing('world')]
class B { 
    public function __construct() {}
}

class Route {
    public function __construct(public string $name) {}
}

#[Attribute(Attribute::TARGET_CLASS)]
class Routing {
    private static $routes = [];
    
    public function __construct(public string $name) {
        static::add(new Route($name));
    }
    
    private function add($route) {
        static::$routes[] = $route;
    }
    
    public static function getRoutes() {
        return static::$routes;
    }
}

$rA = new ReflectionClass(A::class);
$rB = new ReflectionClass(B::class);
$attributeA = $rA->getAttributes()[0];
$attributeB = $rB->getAttributes()[0];
$a = $attributeA->newInstance();
$b = $attributeB->newInstance();
print_r($a);
print_r($b);
print_r($a::getRoutes());

我想这是一个错误。我可以使用旧语法,但这只是一种解决方法,以防万一我找不到解决方案。


问题:

我怎样才能摆脱这个错误消息,或者我的代码中是否遗漏了一些应该存在的东西?

未来读者请注意:此答案写于 2021 年 1 月 15 日

最好的建议可能是“耐心等待”:PHP 8.0.0 于 2020 年 11 月 26 日发布,而 NetBeans 12.2(2020 年 12 月 7 日发布)includes some PHP 8 support there's still an open issue tracking further changes.

特别是,对构造函数 属性 的支持提升为 being worked on in this PR, which is currently labelled as targeting release 12.3, which should be complete in the second half of February 2021

在那之前,您要么不得不忍受 IDE 认为您的来源无效,要么切换到不同的 IDE(PhpStorm 在 version 2020.3, released 3rd December 2020 中包含了必要的更改,如果你负担得起的话)。

顺便说一句,如果从事 NetBeans PHP 功能的任何人看到这一点,您可能想要更新 this marketing page which is the top hit for "netbeans php" 并且目前吹嘘其对 PHP 5.6!