[php-src] Issue #19044: Protected properties do not follow the same scoping rules than methods

From: Date: Sat, 05 Jul 2025 21:45:17 +0000
Subject: [php-src] Issue #19044: Protected properties do not follow the same scoping rules than methods
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-250379@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/19044 Author: bwoebi ### Description The following code (https://3v4l.org/7Xf05#v8.4.10): ```php <?php abstract class P { abstract protected $foo { get; } } class C1 extends P { protected $foo = 1; } class C2 extends P { protected $foo = 2; static function foo($c) { return $c->foo; } } var_dump(C2::foo(new C2)); var_dump(C2::foo(new C1)); ``` Resulted in this output: ``` int(2) Fatal error: Uncaught Error: Cannot access protected property C1::$foo in /in/7Xf05:14 Stack 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): ``` <?php abstract class P { abstract protected function foo(); } class C1 extends P { protected function foo() { return 1; } } class C2 extends P { protected function foo() { return 2; } static function doFoo($c) { return $c->foo(); } } var_dump(C2::doFoo(new C2)); var_dump(C2::doFoo(new C1)); ``` results in the expected ``` int(2) int(1) ``` ### PHP Version ```plain PHP 8.4.10 ``` ### Operating System _No response_

« previous php.bugs (#250379) next »