You are here: gloabl & reference behavior question? « PHP « IT news, forums, messages
gloabl & reference behavior question?

Posted by Surendra Singhi on 07/21/05 01:39

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/

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация