gloabl & reference behavior question?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

(1)
When I try this code:
<?php

    $var_global =" stuff";
    function f1() {
      global $var_global;
      $var_local = array(1,2);
      $var_global =& $var_local;
    }
    f1();
    print_r($var_global);
?>
I get the output:

stuff

where as I was expecting junk value or null.


My question is that, because the array is created locally and we
pass it by reference (without copying) so on the exit of function, its value
is lost, but how does the global variable gets back its old value?

Is it something which is not defined by the PHP language reference and is
implementation specific? And in this case instead of giving the global
variable some junk value or null value, the implementation decides to store
the old values?

Thanks.
-- 
Surendra Singhi

http://www.spikesource.com

http://www.public.asu.edu/~sksinghi/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux