[php-src] Issue #14843: `#[Override]` throws when used on function of trait

From: Date: Sat, 06 Jul 2024 13:39:40 +0000
Subject: [php-src] Issue #14843: `#[Override]` throws when used on function of trait
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-247236@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/14843 Author: nickdnk ### Description The following code: ```php <?php trait MyTrait { abstract public static function foo(): void; public function bar(): void { echo 'Bar parent!' . PHP_EOL; } } class MyClass { use MyTrait; #[\Override] // This works, but gives an error in PHPStorm (?) public static function foo(): void { echo 'Foo overridden!' . PHP_EOL; } //#[\Override] // This causes a compiler error if uncommented public function bar(): void { echo 'Bar overridden!' . PHP_EOL; } } $class = new MyClass(); $class->foo(); $class->bar(); ``` Resulted in this output: ``` // If uncommented Foo overridden! // indicating that both methods are in fact overridden. Bar overridden! // if uncommented Fatal error: MyClass::bar() has #[\Override] attribute, but no matching parent method exists ``` But I expected this output instead: I would expect #[Override] to not throw *or* the override to not work *or* that #[Override] would also throw on static methods. I am unsure which parts of this are intended or not, but it's a little confusing, which PHPStorm has gotten wrong as well, as it will say both of these are invalid, which clearly is not the case: <img width="497" alt="Screenshot 2024-07-06 at 15 37 33" src="https://github.com/php/php-src/assets/8411314/6f9fb3b8-7db2-4164-9660-b5ec5f03c10e"> ### PHP Version 8.3.7 ### Operating System macOS homebrew CLI

« previous php.bugs (#247236) next »