On Oct 15, 2024, at 2:11 PM, Larry Garfield <la...@garfieldtech.com> wrote:
> 
> I think folks are operating with different definitions of "BC Break".
> 
> Consider:
> 
> // Foreign.php
> 
> class Foreign {
>  public function __construct(public string $name) {}
> }
> 
> // My code:
> 
> $f = new Foreign('beep');
> $rProp = (new ReflectionObject($f))->getProperty('name');
> if ($rProp->isPublic()) {
>  $f->name = 'boop';
> }
> 
> Under PHP 8.0, this code works.
> Upgrading to PHP 8.1, this code *still works* exactly the same.  Therefore, 
> there is no BC break.
> Upgrading to PHP 8.4, this code *still works* exactly the same.  Therefore, 
> there is no BC break.
> 
> Now, someone edits Foreign.php in 8.1 to read:
> 
> class Foreign {
>  public function __construct(public readonly string $name) {}
> }
> 
> Now, my code will fail, because isPublic() does not guarantee "is writeable" 
> anymore.  
> 
> Is this a BC break in PHP?
> 
> I can see the argument either way, personally, but I tend toward no.  One PHP 
> version to the next should always be safe to upgrade an *existing* code base. 
>  Just swap out the PHP binary and it should still work the same.  We want 
> that.  However, once you start modifying any part of the code (including 
> dependencies), all bets are off.
> 
> Suppose some library switched from using annotations to using attributes.  
> Any other code that was looking for those annotations is now broken, but it 
> would be ridiculous to accuse attributes of having broken BC in PHP.  Or 
> ancient PHP 4 code that just assumed all properties were public (which they 
> were in PHP 4), now confronted with PHP 5 code that has private properties.  
> Is that a PHP BC break?  Not at all.
> 
> And again, the relevant change here happened in PHP 8.1.  This is only 
> tangentially related to 8.4 at all, because isPublic() has not implicitly 
> meant is-writeable anymore for three years.
> 
> --Larry Garfield

After discussing it and thinking about it for a few days, I agree it's
not a BC break. Existing code should be fine, and larger frameworks
that tend to rely on reflection trickery and such also tend to need
updates for newer PHP. The expectations don't really change.

I don't think we need to rush a solution in for 8.4 as long as we can
implement one with the existing APIs in userland. As Larry mentioned,
readonly (and hooks) already made the previous assumptions invalid by
8.1. As long as we can provide a polyfill and documentation (which
should also cover the readonly case in 8.1 too), I'm OK with deferring
isReadable/isWritable to 8.5.

Reply via email to