Reply to Re: global or $GLOBALS

Your name:

Reply:


Posted by Chung Leong on 05/18/06 18:52

ojorus wrote:
> Hi!
> Just two short questions..:
>
> 1) In a function I want to get the value of a global variable declared
> outside the function. Should I use "global $variable" or $GLOBALS[variable]?
> Are there any differences in performance or other aspects which should make
> me choose the one thing or the other?

Access through $GLOBALS is slightly slower, since it requires two
look-ups: one for the $GLOBALS array, another for the actual element
within the array. Using the global keyword is the preferred method.

> 2) Generally, is it better to pass arguments to the function instead?

Yes, it's in general better to pass arguments. It makes your code more
flexible obviously as you can pass in different arguments. Using global
variables also makes your functions non-reentrant, which is serious
headache in any complex application.

[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

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