<?php
class ShopProduct
{
public $discount = 0;
public $title;
public $producerMainName;
public $producerFirstName;
protected $price;
function __construct($title, $firstName, $mainName, $price)
{
$this->title = $title;
$this->producerFirstName = $firstName;
$this->producerMainName = $mainName;
$this->price = $price;
}
function getSummaryLine(){
$base = "{$this->title} ( {$this->producerMainName}, ";
$base .= "{$this->producerFirstName} )";
return $base;
}
function getProducer() {
return "{$this->producerFirstName} " . "{$this->producerMainName}";
}
function setDiscount(){
$this->discount=$num;
}
public function getPrice()
{
# code...
return ($this->price - $this->discount);
}
}
class ShopProductWriter(){
private $products = array();
public function addProduct( ShopProduct $shopProduct){
$this->product[] = $shopProduct;
}
public function write(){
$str = "";
foreach ($this->products as $shopProduct) {
$str .= "{$shopProduct->title}: ";
$str .= "{$shopProduct->getProducer()}";
$str .= "{$shopProduct->getPrice()}\n";
}
print $str;
}
}
class CDProduct extends ShopProduct {
public $playLength;
function __construct($title, $firstName, $mainName, $price, $playLength){
parent::__construct($title, $firstName, $mainName, $price);
$this->playLength = $playLength;
}
function getPlayLength(){
return $this->playLength;
}
function getSummaryLine(){
$base = parent::getSummaryLine();
$base .= " :Legth of song {$this->playLength}";
return $base;
}
}
class BookProduct extends shopProduct{
public $numPages;
function __construct($title, $firstName, $mainName, $price, $numPages){
parent::__construct($title, $firstName, $mainName, $price);
$this->playLength = $playLength;
}
function getSummaryLine(){
$base = parent::getSummaryLine();
$base .= ": Number of pages - {$this->numPages}";
}
function getProducer() {
return "{$this->producerFirstName} " . "{$this->producerMainName}";
}
function getPrice(){
return $this->price;
}
}
$product2 = new CDProduct("On my own", "Ashes", "Remain", 10.99, 2.53);
$product3 = new CDProduct("On my own", "Ashes", "Remain", 10.99, 2.53);
$product4 = new CDProduct("On my own", "Ashes", "Remain", 10.99, 2.53);
$product5 = new CDProduct("On my own", "Ashes", "Remain", 10.99, 2.53);
print write();
- Output for 5.5.24 - 5.5.31, 5.6.8 - 5.6.17, 7.0.0 - 7.0.2
- Parse error: syntax error, unexpected '(', expecting '{' in /in/p5unj on line 42
Process exited with code 255.
preferences:
166.22 ms | 1395 KiB | 28 Q