Reply to Re: gloabl & reference behavior question?

Your name:

Reply:


Posted by Surendra Singhi on 07/22/05 21:46

"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.


--
Surendra Singhi

http://www.spikesource.com

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

[Back to original 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

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