@ 2016-01-07T21:53:50Z <?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();
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.0.0 - 7.0.33 , 7.1.0 - 7.1.25 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.4 , 8.3.6 Fatal error: Uncaught Error: Call to undefined function write() in /in/ZFm2X:110
Stack trace:
#0 {main}
thrown in /in/ZFm2X on line 110
Process exited with code 255 . 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
Fatal error: Uncaught Error: Call to undefined function write() in /in/ZFm2X:110
Stack trace:
#0 {main}
thrown in /in/ZFm2X on line 110
Process exited with code 255 . Output for 5.5.0 - 5.5.38 , 5.6.0 - 5.6.38 Fatal error: Call to undefined function write() in /in/ZFm2X on line 110
Process exited with code 255 . preferences:dark mode live preview
238.61 ms | 402 KiB | 294 Q