tag:blogger.com,1999:blog-8861470730700525370.post1385074653191789345..comments2023-10-02T03:55:44.095-05:00Comments on Fifty Outs: PHP5 References Explained Visuallymohrthttp://www.blogger.com/profile/12160903071209543914noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-8861470730700525370.post-85603836152079557082011-08-19T17:15:45.099-05:002011-08-19T17:15:45.099-05:00This learned me a lot.
What I most notice is:
*O...This learned me a lot.<br /><br />What I most notice is:<br /><br />*Objects are really treated differently from other types in PHP 5. This seems natural and desirable to me, but I'm scared I will be confused if I have to go back to other languages.<br /><br />*There is one case where PHP could manage memory differently. If you have<br /><br />$a = "Manifesto...";<br />$b = $a;<br /><br />PHP is efficient and only stores the string once. However if you have<br /><br />$a = "Manifesto...";<br />$b = $a;<br />$c = &$a;<br /><br />PHP is probably less efficient and stores the string (or other scalar types) twice, once for the group of aliases c and a and once for b.<br /><br /><br />Thank you Monte. If you provide this by pure altruism, I encourage you to license it under a free license. This could be re-used in PHP documentation.Philippe Cloutierhttps://www.blogger.com/profile/11747581543648950065noreply@blogger.comtag:blogger.com,1999:blog-8861470730700525370.post-2679081276100131172011-08-19T14:37:16.043-05:002011-08-19T14:37:16.043-05:00I have now added comments next to each example, se...I have now added comments next to each example, see if that helps!mohrthttps://www.blogger.com/profile/12160903071209543914noreply@blogger.comtag:blogger.com,1999:blog-8861470730700525370.post-21085342043788600102011-08-19T13:43:26.628-05:002011-08-19T13:43:26.628-05:00is_ref=1 because this value is a real refernce. Me...is_ref=1 because this value is a real refernce. Meaning if I change the value of $a, then $c will also be affected. If you notice on the first page $a and $b point to the same value, but is_ref=0. Therefore when $b got a new value, $a retained its value by creating an internal copy.mohrthttps://www.blogger.com/profile/12160903071209543914noreply@blogger.comtag:blogger.com,1999:blog-8861470730700525370.post-41432012307178735602011-08-19T12:31:42.710-05:002011-08-19T12:31:42.710-05:00Thank you. In that case, why is is_ref 1 at the to...Thank you. In that case, why is is_ref 1 at the top of page 2 ( $c = &$a)?<br />BTW, it took me some time to understand the result of $c = &$a, although I could make some sense of it. I didn't understand why $b would be copied due to that. I like the visual representation, but some text explanations could help when even if what happens is clear, the reasons why it happens are not<br /><br />There is some related information on http://www.php.net/manual/en/features.gc.refcounting-basics.php but it doesn't really answer my questions on the above.Philippe Cloutierhttps://www.blogger.com/profile/11747581543648950065noreply@blogger.comtag:blogger.com,1999:blog-8861470730700525370.post-17820261003251808712011-08-17T17:39:07.821-05:002011-08-17T17:39:07.821-05:00PHP keeps an internal indicator on each variable c...PHP keeps an internal indicator on each variable called "is_ref" that determins if it is a reference or not. This is part of how PHP keeps track of reference counts.mohrthttps://www.blogger.com/profile/12160903071209543914noreply@blogger.comtag:blogger.com,1999:blog-8861470730700525370.post-3013662246011550742011-08-17T16:53:51.372-05:002011-08-17T16:53:51.372-05:00Thank you Monte. I would appreciate if the meaning...Thank you Monte. I would appreciate if the meaning of "is_ref" could be clarified.Philippe Cloutierhttps://www.blogger.com/profile/11747581543648950065noreply@blogger.com