Re: Idea to extend language: Explicitly setting variable scope inside user defined function (longer)
| From: | Andrey Hristov | Date: | Mon, 21 Oct 2002 16:16:41 +0000 |
| Subject: | Re: Idea to extend language: Explicitly setting variable scope inside user defined function (longer) | ||
| References: | 1 2 3 4 5 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-89808@lists.php.net to get a copy of this message | ||
----- Original Message -----
From: "NTPT" <ntpt@centrum.cz>
To: "Andrey Hristov" <andrey@webgate.bg>; "Marco Tabini"
<marcot@tabini.ca>
Cc: <php-dev@lists.php.net>
Sent: Monday, October 21, 2002 7:14 PM
Subject: Re: [PHP-DEV] Idea to extend language: Explicitly setting variable
scope inside user defined function (longer)
>
> ----- Original Message -----
> From: "Andrey Hristov" <andrey@webgate.bg>
> To: "Marco Tabini" <marcot@tabini.ca>
> Cc: <php-dev@lists.php.net>
> Sent: Monday, October 21, 2002 12:42 PM
> Subject: Re: [PHP-DEV] Idea to extend language: Explicitly setting
variable
> scope inside user defined function (longer)
>
>
> >
> >
> > > Marco Tabini <marcot@tabini.ca> wrote... :
> > >
> > > Well, you have to admit that the issue of variable scope is the first
> > > thing that hits someone who approaches PHP for the first time and
comes
> > > from other backgrounds, like C or ASP!
> > >
> >
> > For me global vars are bad at all.
> > If you want to use some value in a function then pass it to the function
> > even if you
> > want you can pass an array will variable ammount of vars that has names
as
> > indexes.
>
> Nice idea, i use it sometimes, it works, but ......
>
> real life situation like this:
>
> <?
> $sqlstring=" UPDATE testtable SET
db_value1='$value_1',db_value1='$value_1'
> .....etc db_value_n='$value_n' ";
>
> // now you must produce $passed_variables array , like this
>
>
> // glue code
> $passed_variables['value_1']=$value_1;
> $passed_variables['value_2']=$value_2;
>
> .
> etc
> .
> $passed_variables['value_n']=$value_n;
> // end of glue code
>
> $result = db_query($passed_variables,$sqlstring)
> {
I don't use it like you show but
$result = db_query(array('value_1'=>$value_1, 'value_2'=>$value_2,
'value_n'=>$value_n), $sqlstring);
As you see there are no additional lines.
Regards,
Andrey