3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace A; use C\E , B\D as P; function foo() { echo __NAMESPACE__;} class A\B\D{ function foo() { echo __NAMESPACE__;}} new P; P\foo(); // function calls foo(); // first tries to call "foo" defined in namespace "A" // then calls global function "foo" \foo(); // calls function "foo" defined in global scope my\foo(); // calls function "foo" defined in namespace "A\my" F(); // first tries to call "F" defined in namespace "A" // then calls global function "F" // class references new B(); // creates object of class "B" defined in namespace "A" // if not found, it tries to autoload class "A\B" 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 5.4.0 - 5.4.19
Parse error: syntax error, unexpected '\' (T_NS_SEPARATOR), expecting '{' in /in/LXi5v on line 5
Process exited with code 255.
Output for 5.3.0 - 5.3.27
Parse error: syntax error, unexpected T_NS_SEPARATOR, expecting '{' in /in/LXi5v on line 5
Process exited with code 255.

preferences:
168.03 ms | 1395 KiB | 55 Q