|  | Posted by Jerry Stuckle on 05/08/07 02:10 
Vince Morgan wrote:> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
 > news:kpqdnd8GMfhP36LbnZ2dnUVZ_rOqnZ2d@comcast.com...
 >> Vince,
 >>
 >> Almost - but the assignment into $var is an operation, also.  More below.
 >>
 >> Vince Morgan wrote:
 >>> "Vince Morgan" <vinharAtHereoptusnet.com.au> wrote in message
 >>> news:463f3216$0$15845$afc38c87@news.optusnet.com.au...
 >>>> <?
 >>>> function &get()
 >>>> {
 >>>>  global $r;
 >>>>  return $r;
 >>>> }
 >>>> $r=5;
 >>>> $var=$r;
 >>>> echo $var;//output is 5 as expected.
 >>>> $r=6;
 >>>> echo $var;//output is still 5 as not expected, by me that is ;)
 >>>> $var=$r;
 >>>> echo $var;//output is now 6
 >>>> ?>
 >>> Oooops, getting too late evidently.  I meant to write the following.
 >>> <?
 >>> function &get()
 >>> {
 >>>  global $r;
 >>>  return $r;
 >>> }
 >>> $r=5;
 >>> $var=get();
 >> get() is returning a reference.  But you are assigning a copy into $var.
 >>
 >>> echo $var;//output is 5 as expected.
 >>> $r=6;
 >>> echo $var;//output is still 5
 >>> $var=get();
 >> Same as above.
 >>
 >>> echo $var;//output is now 6
 >>> ?>
 >>>
 >>>
 >> If you change these to
 >>
 >> $var = $get();
 >>
 >> You will get 5, 6 and 6, respectively.
 >>
 >> There's a discussion about it at
 >> <http://www.php.net/manual/en/language.references.return.php>
 >>
 > Thank you for taking the time Jerry.
 > I haven't the time just yet to read the entire linked article, but have read
 > enough already to realize my understanding of references in php is
 > incorrect.
 > Thanks again,
 > Vince
 >
 >
 
 Vince,
 
 I wouldn't say it's incorrect.  Maybe just a little incomplete. :-)
 
 --
 ==================
 Remove the "x" from my email address
 Jerry Stuckle
 JDS Computer Training Corp.
 jstucklex@attglobal.net
 ==================
  Navigation: [Reply to this message] |