note 101376 added to language.references
| From: | caslav dot sabani at gmail dot com | Date: | Mon, 13 Dec 2010 15:48:59 +0000 |
| Subject: | note 101376 added to language.references | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-174844@lists.php.net to get a copy of this message | ||
Consider this when using references:
<?php
class Test
{
public $var;
}
$a = new Test();
$a->var = 10;
$b = $a;
$c =& $a;
echo '<b>$a</b>:';
echo '<pre>';
print_r( $a );
echo '</pre>';
unset( $b );
echo 'after <b>unsetting</b> $b <b>$a</b> is:';
echo '<pre>';
print_r( $a );
echo '</pre>';
unset( $c );
echo 'after <b>unsetting</b> $c <b>$a</b> is:';
echo '<pre>';
print_r( $a );
echo '</pre>';
$a = new Test();
$a->var = 10;
$b = $a;
$c =& $a;
echo '<b>$a</b>:';
echo '<pre>';
print_r( $a );
echo '</pre>';
$b = NULL;
echo 'after <b>nulling</b> $b <b>$a</b> is:';
echo '<pre>';
print_r( $a );
echo '</pre>';
$c = NULL;
echo 'after <b>nulling</b> $c <b>$a</b> is:';
echo '<pre>';
print_r( $a );
echo '</pre>';
?>
This outputs:
$a:
Test Object
(
[var] => 10
)
after unsetting $b $a is:
Test Object
(
[var] => 10
)
after unsetting $c $a is:
Test Object
(
[var] => 10
)
$a:
Test Object
(
[var] => 10
)
after nulling $b $a is:
Test Object
(
[var] => 10
)
after nulling $c $a is:
----
Server IP: 69.147.83.197
Probable Submitter: 89.216.241.4
----
Manual Page -- http://www.php.net/manual/en/language.references.php
Edit -- https://master.php.net/note/edit/101376
Del: integrated -- https://master.php.net/note/delete/101376/integrated
Del: useless -- https://master.php.net/note/delete/101376/useless
Del: bad code -- https://master.php.net/note/delete/101376/bad+code
Del: spam -- https://master.php.net/note/delete/101376/spam
Del: non-english -- https://master.php.net/note/delete/101376/non-english
Del: in docs -- https://master.php.net/note/delete/101376/in+docs
Del: other reasons-- https://master.php.net/note/delete/101376
Reject -- https://master.php.net/note/reject/101376
Search -- https://master.php.net/manage/user-notes.php