Posted by Berislav Lopac on 07/06/05 14:41
Tony wrote:
> Berislav Lopac wrote:
>> Even better -- don't use global variables.
>
> Easier said than done. There are times when globals are the best
> solution. There IS a reason they're available...
You can (and should) always pass a global variable as a function parameter.
There is no effective difference between:
function foo($bar)
{
global $foobar;
return $bar + $foobar;
}
and
function foo($bar, &$foobar)
{
return $bar + $foobar;
}
The difference is that when you call the second example you have to pass one
more argument, but that prevents the encapsulation of the function, making
it reusable and independent of the outside world.
Berislav
Navigation:
[Reply to this message]
|