{ if ($this->chain == FALSE) { return $this->name = $age; } else { $this->name = $age; return $this; } } public function introduce() { if (empty($this->name)) { print "I need a name!"; } else { if (empty($this->age)) { print "I dont have an age!"; } else { printf("Hello there, my name is <b>%s</b> and I am <b>%s</b> years old.", $this->name, $this->age); } } } } //$hello = new Hello(); $name = "Tung"; $age = 17; //echo $hello->setName($name); //echo $hello->setAge($age); //$hello->introduce(); $hello = new Hello(true); // chaining method $hello->setName($name)->setAge($age)->introduce();