3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CartEntry { //changing to private private $Price; private $Quantity; public function __construct($Price, $Quantity) { $this->Price = $Price; $this->Quantity = $Quantity; } public function ReturnPrice() { return $this->Price; } public function ReturnQuantity() { return $this->Quantity; } }// end class class CartContents { //Changed to private private $items = array(); public function __construct($items) { $this->items = $items; } public function ReturnItems() { return $this->items; } } // end class class Order { private $cart; private $salesTax; function __construct( float $salesTax, Array $items){ $this->salesTax = $salesTax; $this->items = $items; } function OrderTotal() { $cartTotal = 0; for ($i=0, $max=count($this->items); $i < $max; $i++) { $cartTotal += $this->items[$i]->ReturnPrice() * $this->items[$i]->ReturnQuantity(); } $cartTotal += $cartTotal * $this->salesTax; return $cartTotal; } } $entry1 = new CartEntry(1.2, 120); $entry2 = new CartEntry(2.2,200); $mycart = new CartContents([$entry1,$entry2]); $items = $mycart->ReturnItems(); $mytax = 0.2; //Items variable can be changed with mycart $myorder = new Order($mytax,$items); echo $myorder->OrderTotal();
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Creation of dynamic property Order::$items is deprecated in /in/Xbnls on line 44 700.8

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:
61.01 ms | 401 KiB | 8 Q