3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php <?php interface iPropulsion { public function accelerate(); public function decelerate(); } interface iOrdonance { public function lockOn(); public function fire(); } class CarEngine implements iPropulsion { public function accelerate() { return "increase revs to 3000... This should shake yer kidney stones..."; } public function decelerate() { return "decrease revs to 1000"; } } class JetEngine implements iPropulsion { public function accelerate() { return "increase revs to 20000... To the ends of skies..."; } public function decelerate() { return "decrease revs to 5000"; } } class Cannon implements iOrdonance { public function lockOn() { return "Srsly?! Just point and shoot, how hard is that..."; } public function Fire() { return "Dagagagagaga!"; } } class Rocket implements iOrdonance { public function lockOn() { return "Beep... Beep... Beeeeeeeeeeeep..."; } public function Fire() { return "Swhooosh! Ka-Boom!"; } } class Vehicle { private $propulsion = null; private $ordonance = null; public function __construct(iPropulsion $propulsion, iOrdonance $ordonance) { $this->propulsion = $propulsion; $this->ordonance = $ordonance; } public function start() { print $this->propulsion->accelerate() . PHP_EOL; } public function stop() { print $this->propulsion->decelerate() . PHP_EOL; } public function lockOn() { print $this->ordonance->lockOn() . PHP_EOL; } public function fire() { print $this->ordonance->fire() . PHP_EOL; } public function setPropulsion(iPropulsion $propulsion) { $this->propulsion = $propulsion; } public function setOrdonance(iOrdonance $ordonance) { $this->ordonance = $ordonance; } } print "Hey I want a new fighting vehicle... With a Cannon!" . PHP_EOL; $fighter = new Vehicle(new CarEngine(), new Cannon()); print "Peel off" . PHP_EOL; $fighter->start(); print "Hey I want some target practice :)" . PHP_EOL; print "Going to lock on the target" . PHP_EOL; $fighter->lockOn(); print "Time to blow stuff up" . PHP_EOL; $fighter->fire(); print "This sux, moving too slow :(" . PHP_EOL; $fighter->stop(); print "I need a better engine, mekkaniku-san, and rockets, lotsalotsa rockets, kthxbai" . PHP_EOL; $fighter->setPropulsion(new JetEngine()); $fighter->setOrdonance(new Rocket()); print "Once again into the fray" . PHP_EOL; $fighter->start(); print "Going to lock on the target, hopefully this will go better than last time" . PHP_EOL; $fighter->lockOn(); print "Yeeehaw" . PHP_EOL; $fighter->fire(); print "Control, one bogey down" . PHP_EOL;
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.4.32
Parse error: syntax error, unexpected '<' in /in/QIqLt on line 2
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 '<' in /in/QIqLt on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/QIqLt on line 2
Process exited with code 255.