<?php
/// klasy
class ProductClass{
protected $prodName;
protected $authorName;
protected $prodPrice;
public function __construct( $prodName, $authorName, $prodPrice)
{
$this->prodName = $prodName;
$this->authorName = $authorName;
$this->prodPrice = $prodPrice;
}
public function getProdName(){
return $this->prodName;
}
public function getAuthorName(){
return $this->authorName;
}
public function getPrice(){
return $this->prodPrice;
}
public function setTest($test){
$this->test = $test;
}
}
class BookClass extends ProductClass{
private $pagesNum;
private $releaseYear;
public function __construct( $prodName, $authorName, $prodPrice, $pagesNum, $releaseYear){
parent::__construct( parent::getProdName(), parent::getAuthorName(), parent::getPrice() );
$this->pagesNum = $pagesNum;
$this->releaseYear = $releaseYear;
}
public function getPages(){
return $this->pagesNum;
}
public function getRelDate(){
return $this->releaseYear;
}
public function getAttr() : Array{
return Array($this->prodName, $this->authorName, $this->prodPrice, $this->pagesNum, $this->releaseYear);
}
public function getTest(){
return $this->test;
}
}
$obj1 = new BookClass("Ksiega", "Franek", 344, 23, 1998);
var_dump($obj1->getAttr());
Czy ktos moze mi wytlumaczyc dlaczego to powyzej zwraca:
array(5) { [0]=> NULL [1]=> NULL [2]=> NULL [3]=> int(23) [4]=> int(1998) }
dlaczego tutaj te nulle? czemu wartosci / zmienne nie sa przekazywane do dziecka?