3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php trait Adder { public function calculate(int $x, int $y) { echo $x + $y; } } trait Subtractor { public function calculate(int $x, int $y) { echo $x - $y; } } class StupidCalc { use Adder { calculate as public add; } use Subtractor { calculate as public sub; } function maybeAdd(int $x, int $y) { $this->add($x, $y); } function maybeSub(int $x, int $y) { $this->sub($x, $y); } } $calc = new StupidCalc(); $calc->maybeAdd(3, 2); $calc->maybeSub(3, 2);
Output for 7.0.0 - 7.3.0
Fatal error: Trait method calculate has not been applied, because there are collisions with other trait methods on StupidCalc in /in/JsA0o on line 15
Process exited with code 255.
Output for hhvm-3.15.4
Fatal error: Uncaught Error: more than one trait contains method 'calculate' in /in/JsA0o:15 Stack trace: #0 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.38
Fatal error: Trait method calculate has not been applied, because there are collisions with other trait methods on StupidCalc in /in/JsA0o on line 31
Process exited with code 255.