<?php
class ShopProduct
{
public
$numPages,
$playLength,
$title,
$producerMainName,
$producerFirstName,
$price;
function __construct($title, $firstName, $mainName, $price, $numPages=0, $playLength=0)
{
$this->title = $title;
$this->producerFirstName = $firstName;
$this->producerMainName = $mainName;
$this->price = $price;
$this->numPages = $numPages;
$this->playLength = $playLength;
}
function getProducer()
{
return
"{$this->producerFirstName} ".
"{$this->producerMainName}";
}
function getSummaryLine()
{
$base = "$this->title ({$this->producerMainName},";
$base .= "{$this->producerFirstName})";
return $base;
}
}
class CdProduct extends ShopProduct
{
function getPlayLength()
{
return $this->playLength;
}
function getSummaryLine()
{
$base = "{$this->title} ({$this->producerMainName},";
$base .= "{$this->producerFirstName})";
$base .= ": Playing time - {$this->playLength}";
return $base;
}
}
class BookProduct extends ShopProduct
{
function getNumberOfPages()
{
return $this->numPages;
}
function getSummaryLine()
{
$base = "{$this->title} ({$this->producerFirstName},";
$base .= "{$this->producerFirstName})";
$base .= ": Page count - {$this->numPages}";
return $base;
}
}
$product2 = new CdProduct("Exile on Coldharbour lane", "The " . "Alabama 3", 10.99, null, 60.33);
print "artist: {$product2->getProducer()}\n";
print "Summary: {$product2->getSummaryLine()}\n";
It's more a case of this I'm not quite sure about yet, sure I can print static stuff but I will need to be able to dynamically generate stuff too
$product2 = new CdProduct("Exile on Coldharbour lane", "The " . "Alabama 3", 10.99, null, 60.33);
print "artist: {$product2->getProducer()}\n";
print "Summary: {$product2->getSummaryLine()}\n";