3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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();
based on 1rDVk
Output for 7.0.0 - 7.2.0
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.4.11 - 5.6.28
Parse error: syntax error, unexpected 'class' (T_CLASS) in /in/6KqNu on line 25
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected T_CLASS in /in/6KqNu on line 25
Process exited with code 255.