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