Sara Golemon wrote:
Every "variable" in PHP is a pair.
>
> [cut]

$foo = 1;

/*    $foo (label)  -------->    1 (value) (is_ref=0, refcount=1)   */

$bar = &$foo;

/*   $foo (label) ---------->    1 (value)  */
/*   $bar (label) -------/         is_ref=1, refcount=2 */

Hope that helps.

-Sara

Thanks for the clear explanation :). I understood that in PHP 5 objects are automatically referenced when assigned, and 'primary types' like int, bool, string are normally copied when assigned.


When I do a (very rough) benchmark with strings/ints, assigning (and thus copying) a 1000 bytes string isn't significantly slower than referencing it. Also: memory usage is exactly the same.

Is there any situation in which one might *manually* want to reference a variable instead of assigning it (like: $x =& $y)?

Bert

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to