Re: Protected inheritance hierarchies
| From: | Jonathan Vollebregt | Date: | Sat, 02 Aug 2025 12:55:50 +0000 |
| Subject: | Re: Protected inheritance hierarchies | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-128368@lists.php.net to get a copy of this message | ||
On 8/2/25 11:07 AM, Rob Landers wrote:
It's not an edge case, in C2, you redefine a protected variable with the same name and shadowed the original $v. That $v is different than C's $v. It's easiest to see this with static access: https://3v4l.org/0SRWb#v8.4.10 <https://3v4l.org/0SRWb#v8.4.10> However, I don't know of any way to unshadow a property from $this to access the ancestor's value (other than using private access), but it exists and takes up memory; just accessing it is the hard part. — RobAh I see, thanks. Both getProperties and array casting clobber the shadowed protected properties (Unlike private properties) but you can access the property with reflection by reflecting the parent class. Could it be considered a bug that my first example produces a fatal error instead of trying to access the shadowed parent property that it has access to and is typed to use? I guess that would introduce either too much of a performance penalty recursively checking access for each protected property read, or too much complexity trying to pin down the variable type at parse time. Thanks for the info!