note 44644 added to language.references.return

From: Date: Wed, 11 Aug 2004 22:08:45 +0000
Subject: note 44644 added to language.references.return
Groups: php.notes 
Request: Send a blank email to php-notes+get-74500@lists.php.net to get a copy of this message
I have found references quite dificult to understand. I tested them for a while and finaly understood (hopefully ;-). So, look at this example: <? function &fun() { static $a = 5; return $a; } $x = &fun(); $x++; print $x; print(fun()); ?> This works as desired - $a and $x are the same vars. But if you remove any of the &'s the result will be different. I.e (upper reference romoved): <? function fun() { static $a = 5; return $a; } $x = &fun(); $x++; print $x; print(fun()); ?> In one moment (during returning in above code), the copy, instead of reference, will be used and, at the end, $a and $x will be different vars. I hope it wll help someone. Good luck. ---- Manual Page -- http://www.php.net/manual/en/language.references.return.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+44644 Delete -- http://master.php.net/manage/user-notes.php?action=delete+44644&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+44644&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#74500) next »