View Single Post
ישן 23-01-09, 16:09   # 6
DvirCohen
חבר בקהילה
 
מיני פרופיל
תאריך הצטרפות: Dec 2007
הודעות: 151

DvirCohen לא מחובר  

מה שהוא עשה נקרא 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 

Last edited by DvirCohen; 23-01-09 at 16:12..
  Reply With Quote