3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { protected function test() {} } class B extends A { public function test2($x) { $x->test(); } } class C extends A { protected function test() {} } class D extends C { protected function test() { echo "Hello World!\n"; } } (new B)->test2(new D);
based on cJrNH
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.23, 7.4.0 - 7.4.11, 8.0.0alpha1 - rc2
Hello World!