3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace foo{ echo "1-Inside namespace foo \n"; use My\Full\Classname as Another; use ArrayObject; // importing a global class echo "2-After using ArrayObject line: ".__LINE__."\n"; class Another { public function cname() { echo "line".__LINE__."Method".__METHOD__."\n"; } static function method(){echo "line".__LINE__."Method: ".__METHOD__."\n";} } //This line below is Not working. $obj1 = new namespace\Another; // instantiates object of foo\Another echo "3-After namespace\Another object line: ".__LINE__."\n"; //This line below is Not working. echo "4-".$obj1->method()."\n"; //This line below is Not working. $obj2 = new Another; // instantiates object of class My\Full\Classname echo "5-After Another object line: ".__LINE__."\n"; //This line below is Not working. echo "6-".$obj2->method()."\n"; echo "7-After Another object line: ".__LINE__."\n"; //This line below is Not working. $a = new ArrayObject(array(1)); // instantiates object of ArrayObject echo "8-After ArrayObject line: ".__LINE__."\n"; } namespace My\Full{ class Classname{ public function cname() { echo "line".__LINE__."Method".__METHOD__."\n"; } static function method(){echo "line".__LINE__."Method: ".__METHOD__."\n";} } }
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.7 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Cannot declare class foo\Another because the name is already in use in /in/HELPM on line 7
Process exited with code 255.
Output for 7.0.0 - 7.0.6
1-Inside namespace foo 2-After using ArrayObject line: 6 3-After namespace\Another object line: 15 line11Method: foo\Another::method 4- 5-After Another object line: 20 line35Method: My\Full\Classname::method 6- 7-After Another object line: 23 8-After ArrayObject line: 26
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 in /in/HELPM 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 in /in/HELPM on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/HELPM on line 2
Process exited with code 255.

preferences:
322.26 ms | 401 KiB | 459 Q