@ 2016-01-07T21:54:21Z <?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 ShopProductWriter::write();
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for git.master , git.master_jit , rfc.property-hooks Fatal error: Uncaught Error: Non-static method ShopProductWriter::write() cannot be called statically in /in/InQJ6:110
Stack trace:
#0 {main}
thrown in /in/InQJ6 on line 110
Process exited with code 255 . This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.
Active branches Archived branches Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page
preferences:dark mode live preview
62.75 ms | 401 KiB | 8 Q