note 95154 added to language.references

From: Date: Tue, 15 Dec 2009 20:27:55 +0000
Subject: note 95154 added to language.references
Groups: php.notes 
Request: Send a blank email to php-notes+get-164021@lists.php.net to get a copy of this message
This is to show the affect of changing property of object A through another object B when you pass object A as a property of another object B. <?php // data class to be passed to another class as an object class A{ public $info; function __construct(){ $this->info = "eeee"; } } // B class to change the info in A obj class B_class{ public $A_obj; function __construct($A_obj){ $this->A_obj = $A_obj; } public function change($newVal){ $this->A_obj->info = $newVal; } } // create data object from the A $A_obj = new A(); // print the info property echo 'A_obj info: ' . $A_obj->info . '<br/>'; // create the B object and pass the A_obj we created above $B_obj = new B_class($A_obj); // print the info property through the B object to make sure it has the same value 'eeee' echo 'B_obj info: ' . $B_obj->A_obj->info . '<br/>'; // chage the info property $B_obj->change('xxxxx'); // print the info property through the B object to make sure it changed the value to 'xxxxxx' echo 'B_obj info after change: ' . $B_obj->A_obj->info . '<br/>'; // print the info property from the A_obj to see if the change through B_obj has affected it echo 'A_obj info: ' . $A_obj->info . '<br/>'; ?> The result: A_obj info: eeee B_obj info: eeee B_obj info after change: xxxxx A_obj info: xxxxx ---- Server IP: 69.147.83.197 Probable Submitter: 63.249.90.70 ---- Manual Page -- http://www.php.net/manual/en/language.references.php Edit -- https://master.php.net/note/edit/95154 Del: integrated -- https://master.php.net/note/delete/95154/integrated Del: useless -- https://master.php.net/note/delete/95154/useless Del: bad code -- https://master.php.net/note/delete/95154/bad+code Del: spam -- https://master.php.net/note/delete/95154/spam Del: non-english -- https://master.php.net/note/delete/95154/non-english Del: in docs -- https://master.php.net/note/delete/95154/in+docs Del: other reasons-- https://master.php.net/note/delete/95154 Reject -- https://master.php.net/note/reject/95154 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#164021) next »