I am trying to declare a variable, specifically the $publisher variable, but it is not working. I am unsure if I have extended the class correctly.
Books is the main class and Novel is the extended class.
THE PHP CLASSES
class Books {
/* Member variables */
public $price;
public $title;
/* Member functions */
public function setPrice($par){
$this->price = $par;
}
public function getPrice(){
echo $this->price.'<br/>';
}
public function setTitle($par){
$this->title = $par;
}
public function getTitle(){
echo $this->title.'<br/>';
}
public function __construct($par1,$par2){
$this->title = $par1;
$this->price = $par2;
}
}
class Novel extends Books {
public $publisher;
public function setPublisher($par){
$this->publisher = $par;
}
public function getPublisher(){
echo $this->publisher;
}
}
** CALLING THE CLASS **
include 'includes/book.inc.php';
$physics = new Books("Physics for High School" , 2000);
$chemistry = new Books("Advanced Chemistry" , 1200);
$maths = new Books("Algebra", 3400);
$physics->getTitle();
$chemistry->getTitle();
$maths->getTitle();
$physics->getPrice();
$chemistry->getPrice();
$maths->getPrice();
if (class_exists('Novel')) {
echo 'yes';
}
$pN = new Novel();
$pN->setPublisher("Barnes and Noble");
$pN->getPublisher();
** THE RESULT **
Physics for High School
Advanced Chemistry
Algebra
2000
1200
3400
yes
As you can see it does not declare the $Publisher() Value.
My question is What am I missing?