3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php trait Trait1 { public function init() { echo("Trait1 - init\n"); } } trait Trait2 { public function init() { echo("Trait2 - init\n"); } } class Test { use Trait1 { init as private method1trait1; } use Trait2 { init as public method1trait2; } final public function __construct() { $this->init(); $this->method1trait1(); $this->method1trait2(); } public function init() { echo("Test - init\n"); } } $test = new Test(); $reflection = new ReflectionClass( $test ); foreach($reflection->getTraitAliases() as $k => $v) { echo $k.' => '.$v."\n"; }
Output for 5.4.9 - 5.6.30, 7.0.0 - 7.2.8
Test - init Trait1 - init Trait1 - init method1trait1 => Trait1::init method1trait2 => Trait1::init
Output for hhvm-3.22.0
Fatal error: Uncaught Error: more than one trait contains method 'init' in /in/bbc88:-1 Stack trace: #0 {main}
Process exited with code 255.
Output for hhvm-3.11.1 - 3.21.3
Fatal error: Uncaught Error: more than one trait contains method 'init' in /in/bbc88:20 Stack trace: #0 {main}
Process exited with code 255.
Output for hhvm-3.10.1
Fatal error: more than one trait contains method 'init' in /in/bbc88 on line 20
Process exited with code 255.
Output for 5.4.0 - 5.4.8
Test - init Trait1 - init Trait1 - init method1trait1 => (null)::init method1trait2 => (null)::init
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected T_STRING in /in/bbc88 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/bbc88 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/bbc88 on line 3
Process exited with code 255.