[php-src] Issue #20879: `#[Override]` being a fatal E_COMPILE_ERROR leads to bad usability/update hell
| From: | kkmuffme | Date: | Fri, 09 Jan 2026 08:34:05 +0000 |
| Subject: | [php-src] Issue #20879: `#[Override]` being a fatal E_COMPILE_ERROR leads to bad usability/update hell | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-251509@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/20879
Author: kkmuffme
### Description
The following code:
https://3v4l.org/5bkAg#v8.5.1
```php
<?php
class A {
public function run_new() {}
}
class B extends A {
#[Override]
public function run() {}
}
```
Resulted in this output:
```
Fatal error: B::run() has #[\Override] attribute, but no matching parent method exists
```
But I expected this output instead:
```
Warning: B::run() has #[\Override] attribute, but no matching parent method exists
```
A and B are from 2 different libraries/packages/plugins
"A" cannot know that "B" used
#[Override] so they just removed the
method in a new version. Now if "A" is updated by the user (be it via composer where the
common ^1.2 syntax is used, or be it a WordPress/Drupal/... plugin) the user now has a
broken application.
Even if "B" has a new version that has the #[Override] attribute removed, it
would be necessary to first update "B" before updating "A" and to actually know
about this issue in advance before updating.
Since E_COMPILE_ERROR is fatal, any update commands or UI won't work either - also
composer.lock is useless, since it already contains the updated "A". Which means that you
need to completely reinstall it (removing composer.lock and vendor), which results in likely
different versions of other packages than you had installed before unless your composer.json is
extremely tightly versioned and updated and therefore other issues.
If it's a CMS plugin, you essentially are required to manually either downgrade "A"
(if thats even possible) or manually via FTP update "B".
Since there's no real "harm" in there being no matching parent method/property and
since other attributes like #[NoDiscard] also result in a warning instead of a fatal, I
think the E_COMPILE_ERROR of the Override attribute should be changed - retroactively for PHP 8.3 +
8.4 too, as they are most likely affected by this, being older versions and running code that will
have updates available - to a warning only.
### PHP Version
```plain
8.3+
```
### Operating System
_No response_