3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function get_cc() { $calls = debug_backtrace(); if (!isset($calls[1])) { return NULL; } $call = $calls[1]; var_dump($call); if (isset($call['object'])) { return get_class($call['object']); } elseif (isset($call['class'])) { return $call['class']; } } class Bar { public function bar() { return get_cc(); } public static function baz() { return get_cc(); } } class Foo extends Bar { } $bar = new Bar; echo ($bar->bar() === 'Bar' ? 'OK' : 'FAIL'), "\n<br>"; echo (Bar::baz() === 'Bar' ? 'OK' : 'FAIL'), "\n<br>"; $foo = new Foo; echo ($foo->bar() === 'Foo' ? 'OK' : 'FAIL'), "\n<br>"; echo (Foo::baz() === 'Foo' ? 'OK' : 'FAIL'), "\n<br>"; echo (get_cc() === NULL ? 'OK' : 'FAIL'), "\n<br>";
Output for 7.0.0 - 7.1.0
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Bar has a deprecated constructor in /in/ZMHDn on line 22 array(7) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(43) ["function"]=> string(3) "bar" ["class"]=> string(3) "Bar" ["object"]=> object(Bar)#1 (0) { } ["type"]=> string(2) "->" ["args"]=> array(0) { } } array(7) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(44) ["function"]=> string(3) "bar" ["class"]=> string(3) "Bar" ["object"]=> object(Bar)#1 (0) { } ["type"]=> string(2) "->" ["args"]=> array(0) { } } OK <br>array(6) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(45) ["function"]=> string(3) "baz" ["class"]=> string(3) "Bar" ["type"]=> string(2) "::" ["args"]=> array(0) { } } OK <br>array(7) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(47) ["function"]=> string(3) "bar" ["class"]=> string(3) "Bar" ["object"]=> object(Foo)#2 (0) { } ["type"]=> string(2) "->" ["args"]=> array(0) { } } array(7) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(48) ["function"]=> string(3) "bar" ["class"]=> string(3) "Bar" ["object"]=> object(Foo)#2 (0) { } ["type"]=> string(2) "->" ["args"]=> array(0) { } } OK <br>array(6) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(49) ["function"]=> string(3) "baz" ["class"]=> string(3) "Bar" ["type"]=> string(2) "::" ["args"]=> array(0) { } } FAIL <br>OK <br>
Output for 5.1.1 - 5.6.28
array(7) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(43) ["function"]=> string(3) "bar" ["class"]=> string(3) "Bar" ["object"]=> object(Bar)#1 (0) { } ["type"]=> string(2) "->" ["args"]=> array(0) { } } array(7) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(44) ["function"]=> string(3) "bar" ["class"]=> string(3) "Bar" ["object"]=> object(Bar)#1 (0) { } ["type"]=> string(2) "->" ["args"]=> array(0) { } } OK <br>array(6) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(45) ["function"]=> string(3) "baz" ["class"]=> string(3) "Bar" ["type"]=> string(2) "::" ["args"]=> array(0) { } } OK <br>array(7) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(47) ["function"]=> string(3) "bar" ["class"]=> string(3) "Bar" ["object"]=> object(Foo)#2 (0) { } ["type"]=> string(2) "->" ["args"]=> array(0) { } } array(7) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(48) ["function"]=> string(3) "bar" ["class"]=> string(3) "Bar" ["object"]=> object(Foo)#2 (0) { } ["type"]=> string(2) "->" ["args"]=> array(0) { } } OK <br>array(6) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(49) ["function"]=> string(3) "baz" ["class"]=> string(3) "Bar" ["type"]=> string(2) "::" ["args"]=> array(0) { } } FAIL <br>OK <br>
Output for 5.0.5 - 5.1.0
array(6) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(43) ["function"]=> string(3) "bar" ["class"]=> string(3) "Bar" ["type"]=> string(2) "->" ["args"]=> array(0) { } } array(6) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(44) ["function"]=> string(3) "bar" ["class"]=> string(3) "Bar" ["type"]=> string(2) "->" ["args"]=> array(0) { } } OK <br>array(6) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(45) ["function"]=> string(3) "baz" ["class"]=> string(3) "Bar" ["type"]=> string(2) "::" ["args"]=> array(0) { } } OK <br>array(6) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(47) ["function"]=> string(3) "bar" ["class"]=> string(3) "Bar" ["type"]=> string(2) "->" ["args"]=> array(0) { } } array(6) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(48) ["function"]=> string(3) "bar" ["class"]=> string(3) "Bar" ["type"]=> string(2) "->" ["args"]=> array(0) { } } FAIL <br>array(6) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(49) ["function"]=> string(3) "baz" ["class"]=> string(3) "Bar" ["type"]=> string(2) "::" ["args"]=> array(0) { } } FAIL <br>OK <br>
Output for 5.0.0 - 5.0.4
array(6) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(43) ["function"]=> string(3) "bar" ["class"]=> string(3) "Bar" ["type"]=> string(2) "->" ["args"]=> array(0) { } } array(6) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(44) ["function"]=> string(3) "bar" ["class"]=> string(3) "Bar" ["type"]=> string(2) "->" ["args"]=> array(0) { } } OK <br>array(6) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(45) ["function"]=> string(3) "baz" ["class"]=> string(3) "Bar" ["type"]=> string(2) "::" ["args"]=> array(0) { } } OK <br>array(6) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(47) ["function"]=> string(3) "bar" ["class"]=> string(3) "Foo" ["type"]=> string(2) "->" ["args"]=> array(0) { } } array(6) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(48) ["function"]=> string(3) "bar" ["class"]=> string(3) "Foo" ["type"]=> string(2) "->" ["args"]=> array(0) { } } OK <br>array(6) { ["file"]=> string(9) "/in/ZMHDn" ["line"]=> int(49) ["function"]=> string(3) "baz" ["class"]=> string(3) "Bar" ["type"]=> string(2) "::" ["args"]=> array(0) { } } FAIL <br>OK <br>
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/ZMHDn on line 25
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/ZMHDn on line 25
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/ZMHDn on line 25
Process exited with code 255.