* 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
-- 
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about.  No, sir.  Our model is the trapezoid!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to