|
Posted by ZeldorBlat on 10/12/06 12:35
windandwaves wrote:
> Hi Folk
>
> Consider the two code options below. I want to know if it makes more
> sense, in theory, to pass a variable or to make it global
>
> FIRST OPTION --
>
> ...
>
> $data = 5;
>
> $data = dosomething($data)
>
> ...
>
> echo $data;
> exit();
>
> function dosomething($data) {
> $myval = 3;
> $data = $data + $myval;
> return $data;
> }
>
> SECOND OPTION --
> ...
>
> $data = 5;
>
> dosomething()
>
> ...
>
> echo $data;
> exit();
>
> function dosomething() {
> global $data;
> $myval = 3;
> $data = $data + $myval;
> }
First option -- always, always, always.
Navigation:
[Reply to this message]
|