3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php trait ATrait { public static $static_var = __CLASS__; public $var = __CLASS__; public static function get_class_name() { return __CLASS__; } public function get_class_name_obj() { return __CLASS__; } public static function get_class_name2() { return self::$static_var; } public function get_class_name_obj2() { return $this->var; } } trait Indirect { use ATrait; } class SomeClass { use ATrait; } class UsingIndirect { use Indirect; } $r = SomeClass::get_class_name(); var_dump($r); $r = SomeClass::get_class_name2(); var_dump($r); $o = new SomeClass(); $r = $o->get_class_name_obj(); var_dump($r); $r = $o->get_class_name_obj2(); var_dump($r); $r = UsingIndirect::get_class_name(); var_dump($r); $r = UsingIndirect::get_class_name2(); var_dump($r); $o = new UsingIndirect(); var_dump($o); $r = $o->get_class_name_obj(); var_dump($r); $r = $o->get_class_name_obj2(); var_dump($r);
Output for 5.4.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
string(9) "SomeClass" string(9) "SomeClass" string(9) "SomeClass" string(9) "SomeClass" string(13) "UsingIndirect" string(13) "UsingIndirect" object(UsingIndirect)#2 (1) { ["var"]=> string(13) "UsingIndirect" } string(13) "UsingIndirect" string(13) "UsingIndirect"
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected T_STRING in /in/DaeUX on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING in /in/DaeUX on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/DaeUX on line 3
Process exited with code 255.