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 8.2.0 - 8.2.19, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
Deprecated: Creation of dynamic property Order::$items is deprecated in /in/Xbnls on line 44 700.8
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Deprecated: Creation of dynamic property Order::$items is deprecated in /in/Xbnls on line 44 700.8
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
700.8

preferences:
145.8 ms | 403 KiB | 214 Q