<?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();
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