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

Posted by "Richard Lynch" on 07/25/05 04:31

On Fri, July 22, 2005 11:46 am, Surendra Singhi said:
>
> "Richard Lynch" <ceo@l-i-e.com> writes:
>> The & operator is not, as far as I know, defined for an array assignment
>> operation.
>>
>> True, you can use & in the parameter list in some versions to keep PHP
>> from copying the whole array. But that does not legitimatize what you
>> are
>> doing, I don't think.
>
> I never claimed, what I was doing was correct, rather I didn't knew well
> enough that 'PHP is not C++', and I was misunderstanding how reference and
> global variables work in PHP.
>>
>> I could be 100% wrong. I've never even *TRIED* to use a reference to an
>> array because I simply don't want to write code that confusing in the
>> first place.
>
> I don't think it will make the code confusing, but the person looking at
> the
> code should understand how reference and global variables work. Using
> reference variables avoids unnecessary extra copying of objects, and while
> using large arrays it can make a big difference in speed.
>
> The lesson to learn from this thread is that variables declared in a
> function
> as global (using global keyword) are new reference variables to the actual
> global variable. And, so when these global variables in functions are
> assigned
> a new reference, it breaks the old reference and makes them refer to the
> new
> location, and the actual global variable is not affected.
> But in contrast, if the global variables in the function are assigned a
> new
> value, this does changes the value of the variable in the outer global
> scope.

Well, *I* would be confused by the globals, references, and whatnot you've
got running around...

--
Like Music?
http://l-i-e.com/artists.htm

 

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

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