מה שהוא עשה נקרא chaining, לא בדיוק לזה התכוונתי שדיברתי שתלמד על מחלקות בPHP 5, אבל עושים את זה ע"י החזרת אובייקט פשוט..
PHP קוד:
class letters
{
public function A()
{
print "A";
return $this;
}
public function B()
{
print "B";
return $this;
}
public function C()
{
print "C";
return $this;
}
public function numbers()
{
return new numbers;
}
}
class numbers
{
public function one()
{
print 1;
return $this;
}
public function two()
{
print 2;
return $this;
}
}
$letters = new letters;
$letters->A()->B()->C()->numbers()->one()->two();
וsprintf זאת פונקציה שנותנת לך לעצב מחרוזות, לדוגמא:
PHP קוד:
print sprintf("I have %d %s and %d %s", 5, "apples", 0, "oranges"); // I have 5 apples and 0 oranges