3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Shipping { private $company; function __construct(){ $this->company = ""; } function setStrategy($company){ $this->company = $company; } function calculate (Package $package){ return $this->company->calculate($package); } } interface Company { public function calculate(); } class UPS implements Company{ public function calculate($package){ return 45 * $package->weight; } } class USPS implements Company{ public function calculate(Package $package){ return 30 * $package->weight; } } class FedEx implements Company { public function calculate(Package $package){ return 60 * $package->weight; } } class Package { public $weight; function __construct($weight){ $this->weight = $weight; } } $package = new Package(30); $shipping = new Shipping(); $shiping->setStrategy(new UPS()); echo $shipping->calculate($package);
based on R1ndb
Output for 7.0.30 - 7.3.0beta1
Fatal error: Declaration of UPS::calculate($package) must be compatible with Company::calculate() in /in/cHAPU on line 25
Process exited with code 255.
Output for hhvm-3.22.0
Fatal error: Uncaught Error: Declaration of UPS::calculate() must be compatible with that of Company::calculate() in /in/cHAPU:-1 Stack trace: #0 {main}
Process exited with code 255.
Output for hhvm-3.18.5 - 3.21.3
Fatal error: Uncaught Error: Declaration of UPS::calculate() must be compatible with that of Company::calculate() in /in/cHAPU:25 Stack trace: #0 {main}
Process exited with code 255.
Output for 5.6.30
Fatal error: Declaration of UPS::calculate() must be compatible with Company::calculate() in /in/cHAPU on line 25
Process exited with code 255.