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 C;{ //class E //{ // function foo() { echo __NAMESPACE__;}}} namespace{ new F(); // function calls \F\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 not found, it tries to autoload class "F" // static methods/namespace functions from another namespace B\foo(); // calls function "foo" from namespace "A\B" B::foo(); // calls method "foo" of class "B" defined in namespace "A" // if class "A\B" not found, it tries to autoload class "A\B" D::foo(); // using import rules, calls method "foo" of class "D" defined in namespace "B" // if class "B\D" not found, it tries to autoload class "B\D" \B\foo(); // calls function "foo" from namespace "B" \B::foo(); // calls method "foo" of class "B" from global scope // if class "B" not found, it tries to autoload class "B" // static methods/namespace functions of current namespace A\B::foo(); // calls method "foo" of class "B" from namespace "A\A" // if class "A\A\B" not found, it tries to autoload class "A\A\B" \A\B::foo(); // calls method "foo" of class "B" from namespace "A" // if class "A\B" not found, it tries to autoload class "A\B" } ?>
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Namespace declaration statement has to be the very first statement or after any declare call in the script in /in/vb9JY on line 3
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.12 - 7.3.33, 7.4.0 - 7.4.33
Fatal error: Uncaught Error: Class 'F' not found in /in/vb9JY:16 Stack trace: #0 {main} thrown in /in/vb9JY on line 16
Process exited with code 255.
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.36, 5.6.0 - 5.6.28
Fatal error: Class 'F' not found in /in/vb9JY on line 16
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/vb9JY on line 2
Process exited with code 255.
Output for 4.3.0 - 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/vb9JY on line 2
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/vb9JY on line 2
Process exited with code 255.

preferences:
228.12 ms | 401 KiB | 348 Q