<?php
class Product
{
private $id;
private $name;
private $price;
private $quantity;
public function getId()
{
return $this->id;
}
public function setId($id)
{
$this->id = $id;
}
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
}
public function getPrice()
{
return $this->price;
}
public function setPrice($price)
{
$this->price = $price;
}
public function getQuantity()
{
return $this->quantity;
}
public function setQuantity($quantity)
{
$this->quantity = $quantity;
}
}
$product = new Product();
$product->setId('p01');
$product->setName('name 1');
$product->setPrice(4.5);
$product->setQuantity(2);
echo 'Product Info';
echo '<br>id: ' . $product->getId();
echo '<br>name: ' . $product->getName();
echo '<br>price: ' . $product->getPrice();
echo '<br>quantity: ' . $product->getQuantity();
echo '<br>total: ' . ($product->getPrice() * $product->getQuantity());
?>
Product Info
id: p01
name: name 1
price: 4.5
quantity: 2
total: 9