3v4l.org

run code in 300+ PHP versions simultaneously
<?php class BaseFoo { } class Foo extends BaseFoo { protected function greet($subject) { echo "Hello $subject!"; } public function callStatic($className, $methodName) { $parameters = func_get_args(); $parameters = array_slice($parameters, 2); // Remove $className and $methodName if ($className === 'parent') { $className = parent::class; } return call_user_func_array($className . '::' . $methodName, $parameters); } } class Bar extends Foo { public function publicGreet($subject) { $this->callStatic('parent', 'greet', $subject); } } $b = new Bar(); $b->publicGreet('World');
Output for 8.0.10 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, class BaseFoo does not have a method "greet" in /in/dSW76:15 Stack trace: #0 /in/dSW76(22): Foo->callStatic('BaseFoo', 'greet', 'World') #1 /in/dSW76(27): Bar->publicGreet('World') #2 {main} thrown in /in/dSW76 on line 15
Process exited with code 255.
Output for 8.0.0 - 8.0.9
Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($function) must be a valid callback, class BaseFoo does not have a method "greet" in /in/dSW76:15 Stack trace: #0 /in/dSW76(22): Foo->callStatic('BaseFoo', 'greet', 'World') #1 /in/dSW76(27): Bar->publicGreet('World') #2 {main} thrown in /in/dSW76 on line 15
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'BaseFoo' does not have a method 'greet' in /in/dSW76 on line 15

preferences:
239.55 ms | 403 KiB | 332 Q