לוגו אתר Fresh          
 
 
  אפשרות תפריט  ראשי     אפשרות תפריט  צ'אט     אפשרות תפריט  מבזקים     אפשרות תפריט  צור קשר     חץ שמאלה ‎print ‎"Hello World!"; if‎ ‎not rules.‎know ‎then rules.‎read(); חץ ימינה  

לך אחורה   לובי הפורומים > מחשבים > תכנות ובניית אתרים
שמור לעצמך קישור לדף זה באתרי שמירת קישורים חברתיים
תגובה
 
כלי אשכול חפש באשכול זה



  #9  
ישן 25-05-2008, 16:12
  משתמש זכר eXtruct eXtruct אינו מחובר  
 
חבר מתאריך: 27.10.05
הודעות: 1,067
בתגובה להודעה מספר 8 שנכתבה על ידי DCD שמתחילה ב "[QUOTE]בקשר להעברת מחלקה,..."

אין לי מידע מהאתר של PHP אבל הנא מהאתר של ZEND

http://devzone.zend.com/article/171...-PHP-5#Heading3
ציטוט:
קוד PHP:
 class Person {
    var 
$name;
    function 
getName() {
        return 
$this->name;
    }
    function 
setName($name) {
        
$this->name $name;
    }
    function 
Person($name) {
        
$this->setName($name);
    }
}

function 
changeName($person$name) {
    
$person->setName($name);
}

$person = new Person("Andi");
changeName($person"Stig");
print 
$person->getName(); 

In PHP 4, this piece of code would print out "Andi". The reason is that we pass the object $person to the changeName() function by-value, and thus, $person is copied and changeName() works on a copy of $person.

This behavior is not very intuitive, as many developers would expect the Java-like behavior. In Java variables actually hold a handle (or pointers) to the object, and therefore, when it is copied only the handle and not the entire object is duplicated.
There were two kinds of users in PHP 4, the ones who were aware of this problem and the ones who weren't. The latter would usually not notice this problem and their code was written in a way where it didn't really matter if the problem existed or not. Surely some of these people had sleepless nights trying to track down weird bugs which they couldn't pinpoint. The former group dealt with this problem by always passing and assigning objects by reference. This would prevent the engine from copying their objects but would be quite a headache as the code included numerous & signs.

The old object model not only led to the above-mentioned problems but also led to fundamental problems that prevented implementing some additional features on top of the existing object model.

In PHP 5, the infrastructure of the object model was rewritten to work with object handles. Unless you explicitly clone an object by using the clone keyword you will never create behind the scene duplicates of your objects. In PHP 5, there is neither a need to pass objects by reference nor assigning them by reference.

Note: Passing by reference and assigning by reference is still supported, in case you want to actually change a variable's content (whether object or other type).


ד"א מה שמוזר זה שב PHP5 כבר אין צורך להיתשמש ב var לפני משתנה מחלקה, כמו כן ניתן להישתמש ב __construct() בשביל פונקצית בנאי במקום בשם של המחלקה, מוזר שבדוגמא שלהם הם עדיין משתמשים בסינטקס של PHP4.

נערך לאחרונה ע"י eXtruct בתאריך 25-05-2008 בשעה 16:14.
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
תגובה

כלי אשכול חפש באשכול זה
חפש באשכול זה:

חיפוש מתקדם
מצבי תצוגה דרג אשכול זה
דרג אשכול זה:

מזער את תיבת המידע אפשרויות משלוח הודעות
אתה לא יכול לפתוח אשכולות חדשים
אתה לא יכול להגיב לאשכולות
אתה לא יכול לצרף קבצים
אתה לא יכול לערוך את ההודעות שלך

קוד vB פעיל
קוד [IMG] פעיל
קוד HTML כבוי
מעבר לפורום



כל הזמנים המוצגים בדף זה הם לפי איזור זמן GMT +2. השעה כעת היא 23:44

הדף נוצר ב 0.05 שניות עם 12 שאילתות

הפורום מבוסס על vBulletin, גירסא 3.0.6
כל הזכויות לתוכנת הפורומים שמורות © 2025 - 2000 לחברת Jelsoft Enterprises.
כל הזכויות שמורות ל Fresh.co.il ©

צור קשר | תקנון האתר