fluentInterface.php
class Person {
private $nachname;
private $vorname;
private $strasse;
private $plz;
private $ort;
function setNachname($nachname) {
$this->nachname = $nachname;
return $this;
}
function setVorname($vorname) {
$this->vorname = $vorname;
return $this;
}
function setStrasse($strasse) {
$this->strasse = $strasse;
return $this;
}
function setPlz($plz) {
$this->plz = $plz;
return $this;
}
function setOrt($ort) {
$this->ort = $ort;
return $this;
}
}
$myPerson = new Person();
$myPerson->setVorname("Max")->setNachname("Mustermann");
$myPerson->setOrt("Musterstadt")->setPlz("1234");
object(Person)#1 (5) {
["nachname":"Person":private]=>
string(10) "Mustermann"
["vorname":"Person":private]=>
string(3) "Max"
["strasse":"Person":private]=>
string(13) "Musterstrasse"
["plz":"Person":private]=>
string(4) "1234"
["ort":"Person":private]=>
string(11) "Musterstadt"
}
Fatal error: Uncaught Error: Cannot use object of type Person as array in /mnt/web307/d1/57/58992457/htdocs/oop/Uebungen/11_fluentInterface/fluentInterface.php:116
Stack trace:
#0 {main}
thrown in /mnt/web307/d1/57/58992457/htdocs/oop/Uebungen/11_fluentInterface/fluentInterface.php on line 116