3v4l.org

run code in 300+ PHP versions simultaneously
<?php class BaseClass { private static $queryClass = 'StaticSqlQuery'; public static function setQueryClass($className) { static::$queryClass = $className; } public static function test() { return forward_static_call(static::$queryClass, 'init'); } } class StaticSqlQuery { public static function init($tableName, $className) { return 'Original call'; } } echo BaseClass::test(); BaseClass::setQueryClass( get_class(new class extends StaticSQLQuery { public static function init($tableName, $className) { return 'My stub'; } }) ); echo BaseClass::test();
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught TypeError: forward_static_call(): Argument #1 ($callback) must be a valid callback, function "StaticSqlQuery" not found or invalid function name in /in/6KqNu:12 Stack trace: #0 /in/6KqNu(12): forward_static_call('StaticSqlQuery', 'init') #1 /in/6KqNu(22): BaseClass::test() #2 {main} thrown in /in/6KqNu on line 12
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
Warning: forward_static_call() expects parameter 1 to be a valid callback, function 'StaticSqlQuery' not found or invalid function name in /in/6KqNu on line 12 Warning: forward_static_call() expects parameter 1 to be a valid callback, function 'class@anonymous' not found or invalid function name in /in/6KqNu on line 12
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Parse error: syntax error, unexpected 'class' (T_CLASS) in /in/6KqNu on line 25
Process exited with code 255.

preferences:
162.23 ms | 402 KiB | 183 Q