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() { 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 MTYrD
Output for 7.1.0 - 7.2.0
Original call Warning: Declaration of class@anonymous::init($tableName, $className) should be compatible with StaticSqlQuery::init() in /in/YeFGk on line 25 Fatal error: Uncaught ArgumentCountError: Too few arguments to function class@anonymous::init(), 0 passed and exactly 2 expected in /in/YeFGk:26 Stack trace: #0 [internal function]: class@anonymous::init() #1 /in/YeFGk(12): forward_static_call(Array) #2 /in/YeFGk(33): BaseClass::test() #3 {main} thrown in /in/YeFGk on line 26
Process exited with code 255.
Output for 7.0.0 - 7.0.20
Original call Warning: Declaration of class@anonymous::init($tableName, $className) should be compatible with StaticSqlQuery::init() in /in/YeFGk on line 25 Warning: Missing argument 1 for class@anonymous::init() in /in/YeFGk on line 26 Warning: Missing argument 2 for class@anonymous::init() in /in/YeFGk on line 26 My stub
Output for 5.4.11 - 5.6.28
Parse error: syntax error, unexpected 'class' (T_CLASS) in /in/YeFGk on line 25
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[', expecting ')' in /in/YeFGk on line 12
Process exited with code 255.