interface Band { public function getName(); public function GetGenre(); public function addMusician(); public function getMusicians(); } interface Musician { public function addInstrument(); public function getInstruments(); public function assignToBand(); public function getMusicianType(); } interface Instrument { public function getName(); public function getCategory(); } class Guitarist implements Musician { private $last; private $first; private $musicianType; private $instruments; private $bandReference; function __construct($first, $last) { $this->last = $last; $this->first = $first; $this->musicianType = "gitarzysta"; } public function getName() { return $this->first . " ". $this->last; } public function addInstrument(Instrument $instrument) { } public function getInstruments() { return $this->instruments; } public function getBand() { return $this->$bandReference; } public function assignBand(Band $band) { $this->$bandReference = $band; } public function getMusicianType() { return $this->musicianType; } public function setMusicianType($musicianType) { $this->musicianType = $musicianType; } } class LeadGuitarist extends Guitarist { function __construct($last, $first) { parent::__construct($last, $first); $this->setMusicianType("główny gitarzysta"); } } class RockBand implements Band { private $bandName; private $bandGenre; private $musicians; function __construct($bandName) { $this->bandName = $bandName; $this->bandGenre = "rock"; } public function getName() { return $this->bandName; } public function getGenre() { return $this->bandGenre; } public function addMusician(Musician $musician) { $musicians->assignToBand($this); } public function getMusicians() { return $this->musicians; } } class Guitar implements Instrument { private $name; private $category; function __construct($name) { $this->name = $name; $this->category = "gitary"; } public function getName() { return $this->name; } public function getCategory() { return $this->category; } } // test Obiektów. $band = new RockBand("Czerwone Zmienne"); $bandMemberA = new Guitarist("Michał", "Zmiennoprzecinkowy"); $bandMemberB = new LeadGuitarist("Grzegorz", "Całkowity"); $bandMemberA->addInstrument(new Guitar("Gibson Les Paul")); $bandMemberB->addInstrument(new Guitar("Fender Stratocaster")); $bandMemberB->addInstrument(new Guitar("Hondo H-77")); $band->addMusician($bandMemberA); $band->addMusician($bandMemberB); foreach($band->getMusicians() as $musician) { foreach($musician->getInstruments() as $instrument) { } }
Cytat
Fatal error: Declaration of Guitarist::addInstrument() must be compatible with that of Musician::addInstrument() in /opt/lampp/htdocs/nauka/index.php on line 26
Cześć

U góry kod php i błąd wie ktoś w czym problem tu jest? bo ja nie umiem sb z tym poradzić:/
obiektowego uczę się pare dni dopiero jak coś...
Z góry thx.

EDIT:
linia 26 nie,
class Guitarist implements Musician {
czyli linia 21 to błąd.
ten fragment porostu nie ma znaczników php i zapominałem się
