3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Product { public $price; public function __construct($price) { $this->price = $price; } } class Calculator { public $modifiers = []; public function __construct(array $modifiers) { $this->modifiers = $modifiers; } public function calculate($value) { foreach ($this->modifiers as $modifier) { $value = $modifier->modify($value); } return $value; } } interface Modifier { function modify($value); } class TaxModifier { public $percent; public function modify($value) { return $value * ($this->percent + 1); } public function __construct($percent) { $this->percent = $percent; } } class DiscountModifier { public $discount; public function modify($value) { return $value - $this->discount; } public function __construct($discount) { $this->discount = $discount; } } $product = new Product(19.95); $calculator = new Calculator([ new TaxModifier(0.07), new TaxModifier(0.08), new DiscountModifier(8.00), ]); echo $calculator->calculate($product->price);
Output for git.master, git.master_jit, rfc.property-hooks
15.05422

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
35.26 ms | 401 KiB | 8 Q