Skip to content

Conversation

@Seldaek
Copy link
Member

@Seldaek Seldaek commented Nov 19, 2025

Closes #551

* @readonly
* @var ?string
*/
public $message;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep using typed properties. Attribute classes should not be autoloaded on PHP 7.x anyway as attributes are not supported.

Regarding the readonly keyword, it might make sense to use conditional class definitions to keep them readonly in PHP 8.1+

Copy link
Member Author

@Seldaek Seldaek Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the problem I had is that Composer's phar compiler is linting the files and that goes boom..

Edit: fixed in https://github.com/composer/composer/pull/12627/files#diff-df7082676f4891241241b23e47108e77b204ff234200bdc4203477d672e1554cR199

Maybe we can merge as is and undo it in #496 ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I did some changes.. not a pro here with this conditional def mess, so please review carefully :D

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The composer compiler already have a list of files excluded from linting to account for the fact that Symfony polyfill packages contain some files loaded conditionally: https://github.com/composer/composer/blob/bfc0e3143841dd156d1099a9c6080e1870b470d2/src/Composer/Compiler.php#L192-L199

That's where the case of typed properties need to be handled IMO (the linter would stick complain about one of the files when using conditional definition files anyway, as the file targeting new PHP versions would still use the new syntaxes)

@stof
Copy link
Member

stof commented Nov 19, 2025

The conditional class using features not supported on PHP 8.0 must be extracted in a separate file that is loaded conditionally. Otherwise, you will still get a parse error on the file (the if doing a PHP version check is resolved at runtime, not before parsing the PHP syntax. It is not a preprocessor macro of C)

@Seldaek
Copy link
Member Author

Seldaek commented Nov 19, 2025

Ok I see.. Then I'm not sure I'll find time for this right now if it gets more complex sorry but got a whole lot of other stuff on my plate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PHP 8.4 polyfill for Deprecated attribute is not compatible with PHP 8.0

2 participants