[php-src] Issue #20878: `#[Override]` on properties leads to unexpected backwards incompatible changes

From: Date: Fri, 09 Jan 2026 08:17:18 +0000
Subject: [php-src] Issue #20878: `#[Override]` on properties leads to unexpected backwards incompatible changes
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-251508@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/20878 Author: kkmuffme ### Description The following code: ```php <?php class A { public string $foo; } class B extends A { #[Override] public string $foo; } ``` https://3v4l.org/om5mJ#v8.5.1 => no error https://3v4l.org/om5mJ#v8.3.29 >Fatal error: Attribute "Override" cannot target property (allowed targets: method) https://3v4l.org/om5mJ#v8.2.30 => no error This creates the weird case where code works fine in older PHP and in the latest PHP but you get a fatal for some versions in between, which means the attribute cannot be used for properties at all for quite some time when you need to support all maintained PHP versions (it's only safe to use from 2029 when PHP 8.3 support ends) Possibly for properties we change it to #[OverrideProperty] (or whatever) to prevent this issue? (and deprecate Override on properties again with 8.6, the OverrideProperty attribute could ship with the next 8.5 version though) The RFC https://wiki.php.net/rfc/override_properties says no backward incompatible changes, however this is quite incompatible, isn't it? ### PHP Version ```plain 8.5 8.3/8.4 <8.3 ``` ### Operating System _No response_

« previous php.bugs (#251508) next »