On Thu, Dec 4, 2025, at 10:47 AM, Nicolas Grekas wrote:
> Le jeu. 4 déc. 2025 à 17:39, Larry Garfield <[email protected]> a écrit :
>> On Thu, Dec 4, 2025, at 8:05 AM, Nicolas Grekas wrote:
>> > Le jeu. 6 nov. 2025 à 00:28, Larry Garfield <[email protected]> a 
>> > écrit :
>> >> In other news, Ilija and I said a year ago that we'd take a swing at 
>> >> adding isReadable/isWriteable methods to ReflectionProperty.  Took a 
>> >> while, but here we are.  A strangely small RFC from us:
>> >> 
>> >> https://wiki.php.net/rfc/isreadable-iswriteable
>> >> 
>> >
>> >
>> > Thanks for this.
>> > I also think the auto-scope is [NOT] a good idea. You state that 90% of 
>> > use 
>> > cases will need this but my experience doesn't back this claim. The 
>> > only cases where I had to check for read/writeable were out of the 
>> > local scope, so I'd say 100% of my experience goes against that 90% 
>> > number ;) Joke aside, it'd be just fine to let ppl be explicit. That's 
>> > better than "oops I forgot to give the correct scope" bugs.
>> >
>> > About magic methods, one unsets a property only to have __get/__set 
>> > called. Existing code works with this assumption. This means we have to 
>> > return true IMHO. Magic methods are just generic hooks also. Which 
>> > means they should behave the same.
>> >
>> > Nicolas
>> 
>> Well, the only people who seem to have an opinion don't like "static", so 
>> we've removed it.  RFC updated.
>> 
>> As for __get/__set, that's so far one vote for ignore (Tim), and one for 
>> always-true (Nicolas).  Not a consensus. :-)
>> 
>> Nicolas, can you clarify with an example if/how ignore would break things?  
>> 
>> I think once we settle that question and the cooldown passes we're ready for 
>> a vote, though at this point that means January.
>> 
>
> I can try to build a synthetic example but the gist is:
> A class that starts with only properties and no __get() should be able 
> to move to a __get()-based hooking in a later version without breaking 
> code that uses isReadable().
> That on its own should be enough to settle the desired behavior :)

So you want to be able to transition from:

class Foo
{
  public private(set) string $name;
}

To

class Foo
{
  private array $vals = [];

  public function __get(string $name)
  {
    return $this->vals[$name] ?? throw new Exception();
  }
}

Is that right?  Because both approaches would result in changes in some 
situations there.

If __get is ignored and the value is set, then a global isReadable check will 
go from true to false in that transition.

If __get always returns true and the value is still uninitialized, a global 
isReadable check will go from false to true in that transition.

Either way, that's not a fully safe transition to make.

--Larry Garfield

Reply via email to