> > 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
Wow! I just learned a whole lotta OO from just this email. Thanks Curt! -- --Matthew Sims --<http://killermookie.org> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php