You are here: Re: global or $GLOBALS « PHP Programming Language « IT news, forums, messages
Re: global or $GLOBALS

Posted by Erwin Moller on 05/18/06 17:59

ojorus wrote:

> Hi!
> Just two short questions..:

Hi,

>
> 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?

Just use:
global $varname;
inside your function.

Don't worry about performance issues for such basic stuff unless you have a
valid reason.

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

That depends.
I think you mean if passing by reference or plain passing?

Passing by reference is faster, because normal passing involves a complete
copy of the variable.
If you pass a variable by reference, the pointer to the object is passed.
a possible handy or harmfull sideeffect of passing by reference is that the
function can change the content of the passed variable.

Read more here:
http://nl3.php.net/manual/en/language.references.php

Happy coding. :-)

regards,
Erwin Moller

>
> Ole J

 

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

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