3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public function func() { echo 'I am the parent'; } } class Bar extends Foo { public function func() { echo 'I am the child'; } } // Create instance of child class $bar = new Bar; // Create reflection class $reflected = new ReflectionClass(get_class($bar)); // Get parent method $method = $reflected->getParentClass()->getMethod('func'); // Invoke method on child object $method->invokeArgs($bar, []);
Output for 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.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
I am the parent

preferences:
120.11 ms | 407 KiB | 5 Q