3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Base { protected $foo = 'Base'; } class Other extends Base { protected $foo = 'Other'; } class Child extends Base { public function bar() { $otherBase = new Other(); echo $otherBase->foo; } } $child = new Child(); $child->bar();
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
Fatal error: Uncaught Error: Cannot access protected property Other::$foo in /in/BODds:6 Stack trace: #0 /in/BODds(9): Child->bar() #1 {main} thrown in /in/BODds on line 6
Process exited with code 255.
Output for 5.6.0 - 5.6.29
Fatal error: Cannot access protected property Other::$foo in /in/BODds on line 6
Process exited with code 255.

preferences:
161.4 ms | 401 KiB | 239 Q