[PropertyInfo] PropertyInfo is not compatible with PHP 8.4
Symfony version(s) affected
7.1.4
Description
In PHP 8.4 we'll have virtual properties and asymmetric visibility.
PropertyInfo considers the following properties writable, although they are not:
final class Foo
{
public private(set) bool $public_private_set;
public protected(set) bool $public_protected_set;
public bool $virtual_no_set_hook { get => true; }
}
A side note. Many Symfony components optimistically state that they are compatible with all future PHP versions (for instance, the PropertyInfo component has "require": { "php": ">=8.2" } in its composer.json). However, this case shows that they are not and cannot be. I've discussed, whether it is a BC break on PHP's side or it isn't, see https://externals.io/message/125772. Symfony should probably reconsider it's PHP constraints.
How to reproduce
https://github.com/vudaltsov/symfony-property-access-php84
Possible Solution
In PHP 8.4 a property is writable if
$reflectionProperty->isPublic()
&& !$reflectionProperty->isReadonly()
&& !$reflectionProperty->isPrivateSet()
&& !$reflectionProperty->isProtectedSet()
&& (!$reflectionProperty->isVirtual() || $reflectionProperty->hasHook(PropertyHookType::Set))
See https://externals.io/message/125740.
Additional Context
No response
Also related to #54180.
Thank you for testing early with new versions of PHP. This way, we can make sure, Symfony is ready when PHP 8.4 is released.
Symfony should probably reconsider it's PHP constraints.
No.
In PHP 8.4 a property is writable if
$reflectionProperty->isPublic() && !$reflectionProperty->isReadonly() && !$reflectionProperty->isPrivateSet() && !$reflectionProperty->isProtectedSet() && (!$reflectionProperty->isVirtual() || $reflectionProperty->hasHook(PropertyHookType::Set))
Sounds good. PR welcome, I suppose.
Symfony should probably reconsider it's PHP constraints.
No.
The problem is that a user with PHP 8.4 can install PropertyInfo or other downstream libraries without any problem only to find out later that it does not work with the new PHP 8.4 features. PropertyInfo 7.1.4 is forever installable in PHP 8.4, this cannot be undone. To my mind this isn't a safe approach.
Here's what comes to my mind. Let's say, PropertyInfo requires php: >=8.2 && <8.4. Then PHP announces the feature freeze period, and the Symfony community has 2 months to ensure forward compatibility with the upcoming PHP version. Once it's done, PropertyInfo 7.1.{next patch version} is released with php: >=8.2 && <8.5 constraint. Then PHP 8.4 is out and everyone's happy, because code does not break. What's wrong with this approach?
PR welcome, I suppose.
I'll try my best to find some time :)
PR welcome, I suppose.
Let's wait a little bit. ReflectionProperty::isReadable()/isWritable() methods might be introduced in PHP 8.4 if approved by RMs, see https://externals.io/message/125772#125795. Theses methods will solve the issue in a much cleaner way.
Meanwhile, the failing tests might be added.
Symfony should probably reconsider it's PHP constraints.
No.
The problem is that […]
Sorry, if I cut you off there. I see that you're very passionate about discussing this topic. For me, this is a topic that I consider settled for more than ten years that we use these strategy on constraints. You've opened this as a bug report to discuss an incompatibility. At least I hope that this was your intention. So please let's focus on that very issue.
If you really really really want to discuss version constraints all over again, please research old discussions on that topic, ask yourself if you really have new insights for that discussion and, if that is the case, open a new issue dedicated to that topic. Don't let the discussion about your imminent problem be derailed by something that you've called a "side note".
Let's wait a little bit.
ReflectionProperty::isReadable()/isWritable()methods might be introduced in PHP 8.4 if approved by RMs, see https://externals.io/message/125772#125795. Theses methods will solve the issue in a much cleaner way.
That would indeed be a welcomed addition. Crossing fingers. 🤞🏻 🙂
PHP 8.4 has been released today. Sadly, ReflectionProperty::isReadable() and ReflectionProperty::isWritable() are not included in PHP 8.4 (ReflectionProperty). 😥