Re: [RFC] isReadable/isWriteable property reflection

From: Date: Wed, 14 Jan 2026 20:00:21 +0000
Subject: Re: [RFC] isReadable/isWriteable property reflection
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-129756@lists.php.net to get a copy of this message
> Le 13 janv. 2026 à 22:30, Larry Garfield <larry@garfieldtech.com> a écrit : > > On Wed, Nov 5, 2025, at 5:24 PM, Larry Garfield wrote: >> 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 > > Hi folks. > > The holiday blackout period is over, and there's nothing else really to discuss on this > PR, so consider this an Intent to Vote notice for the isReadable RFC. > > I'll call the vote later this week, baring any new serious constructive feedback. > > --Larry Garfield Hi, The RFC says: > To use “my current scope,” the static::class construct is an easy way to specify > “whatever class this code is running in.” The code is running in self::class or __CLASS__, not in static::class. ------ As noted in the RFC, isReadable() will give unavoidable false-positives (returning true although attempt to read the property will error). But there is also a false-negative: ```php class C { function __construct( readonly private mixed $foo ) { } function __get($x) { if ($x === 'foo') { return $this->foo; } throw new Error('Undefined property '.$x); } function __isset($x) { if ($x === 'foo') return isset($this->foo); // not true, otherwise isset(new C(null)->foo) will return an incorrect result. } return false; } } $c = new C(null); // will return false, although it is readable var_dump(new ReflectionProperty($c, 'foo')->isReadable(null, $c)); ``` One could skip the __isset() check in order to avoid the false-negative, at the cost of more false-positives. I don’t know what is best, because I tend to avoid __get() like the plague anyway. —Claude

« previous php.internals (#129756) next »