Re: Re: destroying objects in an array in PHP5
| From: | Erik Franzén | Date: | Tue, 27 Jul 2004 21:04:50 +0000 |
| Subject: | Re: Re: destroying objects in an array in PHP5 | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-192021@lists.php.net to get a copy of this message | ||
Thanxs for the help Curt!! Thats a tricky solution, but it works...
This is almost motivating a new method in PHP5: $foo->__destroy() which will destroy the object once and for all... :)
/Erik
Curt Zirzow wrote:
* Thus wrote Erik Franzn:$oObjectB[$i] = &$oObjectA[$i]; The above statement does not matter, because in PHP5 "objects are referenced by handle, and not by value".This is not true. PHP 5 passes objects by reference to functions only. Assignments are treated the same way as php4 externally. <?php /* note: no &$f */ function testfoo($f) { $f->foo = 'testfoo'; } class foo { public $foo; } /* object is passed by reference */ $a = new foo(); $a->foo = 'main'; testfoo($a); var_dump($a); /* ->foo == 'testfoo' */ /* variable is only copied */ $b = $a; $a = null; var_dump($a); /* NULL */ var_dump($b); /* Object 1 */ /* make 2 reference but remove one of them */ $a = new foo(); $b = &$a; unset($a); /* only removes the reference to object #1 */ var_dump($a); /* Undefined */ var_dump($b); /* Object #1 */ /* here is your solution */ /* make 2 references but delete object, 2 variable * references still exits */ $a = new foo(); $b = &$a; $a = null; var_dump($a); /* NULL */ var_dump($b); /* NULL */ /* proof that references still exists */ $b = new foo(); var_dump($a); /* Object #1 */ var_dump($b); /* Object #1 */ Curt