3v4l.org

run code in 300+ PHP versions simultaneously
<?php use B\D, C\E as F; namespace A ; use B\D, C\E as F; // function calls function foo() { echo __NAMESPACE__;} namespace B; use B\D, C\E as F; declare(ticks=1); function tick_handler() { echo "tick_handler() called\n"; } class D { function foo() { echo __NAMESPACE__;}} //* namespace{ use B\D, C\E as F; echo __NAMESPACE__; // function calls*tick_handler()/ new D(); tick_handler(); echo __NAMESPACE__; D:foo(); // first tries to call "foo" defined in namespace "A" // then calls global function "foo" new D(); // using import rules, creates object of class "D" defined in namespace "B" // if not found, it tries to autoload class "B\D" new F(); // using import rules, creates object of class "E" defined in namespace "C" // if not found, it tries to autoload class "C\E" new \B(); // creates object of class "B" defined in global scope // if not found, it tries to autoload class "B" new \D(); // creates object of class "D" defined in global scope // if not found, it tries to autoload class "D" new \F(); // creates object of class "F" defined in global scope // if no ?>
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
Fatal error: Namespace declaration statement has to be the very first statement or after any declare call in the script in /in/R8IlG on line 5
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.2 - 7.3.33, 7.4.0 - 7.4.33
Btick_handler() called B Fatal error: Uncaught Error: Call to undefined function B\foo() in /in/R8IlG:36 Stack trace: #0 {main} thrown in /in/R8IlG on line 36
Process exited with code 255.
Output for 7.3.0 - 7.3.1
Btick_handler() called B Fatal error: Uncaught Error: Call to undefined function foo() in /in/R8IlG:36 Stack trace: #0 {main} thrown in /in/R8IlG on line 36
Process exited with code 255.
Output for 5.3.28 - 5.3.29, 5.4.20 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Btick_handler() called B Fatal error: Call to undefined function B\foo() in /in/R8IlG on line 36
Process exited with code 255.
Output for 5.3.0 - 5.3.27, 5.4.0 - 5.4.19
Btick_handler() called B Fatal error: Call to undefined function B\foo() in /in/JQnaF on line 36
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in /in/JQnaF on line 4
Process exited with code 255.
Output for 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in /in/JQnaF on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_CONSTANT_ENCAPSED_STRING' or `'('' in /in/JQnaF on line 4
Process exited with code 255.
Output for 4.3.0
Parse error: parse error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in /in/R8IlG on line 4
Process exited with code 255.

preferences:
233.42 ms | 401 KiB | 340 Q