- Notifications
You must be signed in to change notification settings - Fork8k
Closed
Description
Description
The following code (https://3v4l.org/7Xf05#v8.4.10):
<?phpabstractclass P {abstractprotected$foo { get; }}classC1extends P {protected$foo =1;}classC2extends P {protected$foo =2;staticfunctionfoo($c) {return$c->foo; }}var_dump(C2::foo(newC2));var_dump(C2::foo(newC1));
Resulted in this output:
int(2)Fatal error: Uncaught Error: Cannot access protected property C1::$foo in /in/7Xf05:14Stack trace:#0 /in/7Xf05(18): C2::foo(Object(C1))#1 {main} thrown in /in/7Xf05 on line 14
But I expected this output instead:
int(2)int(1)
Doing the same with methods works flawlessly (https://3v4l.org/iQo81#v8.4.10):
<?phpabstractclass P {abstractprotectedfunctionfoo();}classC1extends P {protectedfunctionfoo() {return1; }}classC2extends P {protectedfunctionfoo() {return2; }staticfunctiondoFoo($c) {return$c->foo(); }}var_dump(C2::doFoo(newC2));var_dump(C2::doFoo(newC1));
results in the expected
int(2)int(1)
PHP Version
PHP 8.4.10
Operating System
No response