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

Posted by Surendra Singhi on 07/21/05 19:35

"Ford, Mike" <M.Ford@leedsmet.ac.uk> writes:

> On 20 July 2005 23:40, Surendra Singhi wrote:
>
Thanks, for explaining it.
>>
>> (1)
>> When I try this code:
>> <?php
>>
>> $var_global =" stuff";
>> function f1() {
>> global $var_global;
>
> This is equivalent to creating a $var_global which is local to the function,
> and making it be a reference to the global $var_global -- effectively:
>
> $var_global = &$GLOBALS['var_global'];
>
>> $var_local = array(1,2);
>> $var_global =& $var_local;
>
> But this assigns a new reference to $var_local to the (local) $var_global,
> thus breaking the reference to the (global) $var_global -- so the (global)
> $var_global isn't changed by this assignment.

> To do what you're trying to do, you should make use of the $GLOBALS
> superglobal:
>
> $GLOBALS['var_global'] = &$var_local;

Or may I suggest, what I am currently doing (in a much more complex code)
$var_global = $var_local;

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

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