note 68109 added to language.references.unset
| From: | donny at semeleer dot nl | Date: | Thu, 13 Jul 2006 14:10:26 +0000 |
| Subject: | note 68109 added to language.references.unset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-114735@lists.php.net to get a copy of this message | ||
Here's an example of unsetting a reference without losing an ealier set reference
<?php
$foo = 'Bob'; // Assign the value 'Bob' to $foo
$bar = &$foo; // Reference $foo via $bar.
$bar = "My name is $bar"; // Alter $bar...
echo $bar;
echo $foo; // $foo is altered too.
$foo = "I am Frank"; // Alter $foo and $bar because of the reference
echo $bar; // output: I am Frank
echo $foo; // output: I am Frank
$foobar = &$bar; // create a new reference between $foobar and $bar
$foobar = "hello $foobar"; // alter $foobar and with that $bar and $foo
echo $foobar; //output : hello I am Frank
unset($bar); // unset $bar and destroy the reference
$bar = "dude!"; // assign $bar
/* even though the reference between $bar and $foo is destroyed, and also the
reference between $bar and $foobar is destroyed, there is still a reference
between $foo and $foobar. */
echo $foo; // output : hello I am Frank
echo $bar; // output : due!
?>
----
Server IP: 194.109.193.119
Probable Submitter: 62.58.41.165
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/language.references.unset.php
Edit -- http://master.php.net/note/edit/68109
Del: integrated -- http://master.php.net/note/delete/68109/integrated
Del: useless -- http://master.php.net/note/delete/68109/useless
Del: bad code -- http://master.php.net/note/delete/68109/bad+code
Del: spam -- http://master.php.net/note/delete/68109/spam
Del: non-english -- http://master.php.net/note/delete/68109/non-english
Del: in docs -- http://master.php.net/note/delete/68109/in+docs
Del: other reasons-- http://master.php.net/note/delete/68109
Reject -- http://master.php.net/note/reject/68109
Search -- http://master.php.net/manage/user-notes.php