Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting end of file in C:\xampp\htdocs\example.php on line 9
I'm getting this error, but can't see nothing wrong with the code. What did I wrong? Won't return the expected results.
The program is supposed to show: echo $myorder->OrderTotal();
<?php
class CartEntry
{
//changing to private
private $Price;
private $Quantity;
}
//Adding functions to get price and quantity,
public function __construct($Price, $Quantity)
{
$this->Price = $Price;
$this->Quantity = $Quantity;
}
public function ReturnPrice() {
return $this->Price;
}
public function ReturnQuantity() {
return $this->Quantity;
}
}
//
class CartContents
{
//Changed to private
private $items = array();
}
//Adding function to return items, same as above
public function __construct($items) {
$this->items = $items;
}
public function ReturnItems() {
return $this->items;
}
}
class Order
{
private $cart;
private $salesTax;
//cartcontents function removed
function __construct( float $salesTax, Array $items){
$this->salesTax = $salesTax;
$this->items = $items;
}
function OrderTotal()
{
$cartTotal = 0;
for ($i = 0; $i < count($this->items); $i++) {
$cartTotal += $this->items[$i]->Price * $this->items[$i]->Quantity;
}
$cartTotal += $cartTotal * $this->salesTax;
return $cartTotal;
}
}
$entry1 = new CartEntry();
$entry1->Price = 1.2;
$entry1->Quantity = 120;
$entry2 = new CartEntry();
$entry2->Price = 2.2;
$entry2->Quantity = 200;
$mycart = new CartContents();
$mycart->items = array($entry1, $entry2);
$items = $mycart->ReturnItems();
$mytax = 0.2;
//Items variable can be changed with mycart
$myorder = new Order($items, $mytax);
echo $myorder->OrderTotal();
?>