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); } function calculate(int $x, int $y) {} } $calc = new StupidCalc(); $calc->maybeAdd(3, 2); $calc->maybeSub(3, 2);
Output for 7.0.0 - 7.2.9
55
Output for hhvm-3.22.0
Fatal error: Uncaught Error: more than one trait contains method 'calculate' in /in/I2thK:-1 Stack trace: #0 {main}
Process exited with code 255.
Output for hhvm-3.15.4 - 3.21.3
Fatal error: Uncaught Error: more than one trait contains method 'calculate' in /in/I2thK:15 Stack trace: #0 {main}
Process exited with code 255.
Output for 5.6.30
Catchable fatal error: Argument 1 passed to StupidCalc::maybeAdd() must be an instance of int, integer given, called in /in/I2thK on line 37 and defined in /in/I2thK on line 24
Process exited with code 255.