3v4l.org

run code in 500+ PHP versions simultaneously
<?php class x { private function foo() { echo __METHOD__; } function YinX() { $y = new y(); $y->foo(); } } class y extends x { function YinY() { $this->foo(); } } // here, Y can call private foo(); (new x)->YinX(); // here, Y cannot call foo() (new y)->YinY(); ?>
Output for 8.1.32 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.21, 8.5.0 - 8.5.6
x::foo Fatal error: Uncaught Error: Call to private method x::foo() from scope y in /in/rFjoe:14 Stack trace: #0 /in/rFjoe(22): y->YinY() #1 {main} thrown in /in/rFjoe on line 14
Process exited with code 255.

preferences:
30.55 ms | 870 KiB | 4 Q