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() { 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.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Original call Fatal error: Declaration of StaticSQLQuery@anonymous::init($tableName, $className) must be compatible with StaticSqlQuery::init() in /in/YeFGk on line 26
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Original call Warning: Declaration of class@anonymous::init($tableName, $className) should be compatible with StaticSqlQuery::init() in /in/YeFGk on line 26 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.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33
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.5.24 - 5.5.35, 5.6.8 - 5.6.28
Parse error: syntax error, unexpected 'class' (T_CLASS) in /in/YeFGk on line 25
Process exited with code 255.

preferences:
154.68 ms | 401 KiB | 179 Q