Re: Re: Variables within a string
| From: | Jason Wong | Date: | Tue, 12 Mar 2002 03:34:14 +0000 |
| Subject: | Re: Re: Variables within a string | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-88141@lists.php.net to get a copy of this message | ||
On Tuesday 12 March 2002 11:11, Analysis & Solutions wrote:
> On Mon, Mar 11, 2002 at 08:39:16PM -0500, webapprentice wrote:
> > From: Jason Wong <php-general@gremlins.com.hk>
> >
> > On Monday 11 March 2002 11:10, Chris Cocuzzo wrote:
> > > $foo = "Entry for " . $HTTP_POST_VARS["name"];
> >
> > $foo = "Entry for for $HTTP_POST_VARS[name]";
>
> But that's not good programming. Associative arrays should have the key
> quoted in order to avoid confusion with contants. See
>
> http://www.php.net/manual/en/language.types.array.php#language.types.array.
>donts
Inside of double-quoted strings there is no need to single-quote the array
key (in fact it can't be done, gives syntax error). The section of the manual
you quoted states this :)
[snip]
> Now, I wonder why you're even assigning this information to yet another
> varialbe. Why not just use the information straight up?:
> echo "Entry for for $name";
>
> Of course, there are legitimate reasons for your approach, but often new
> programmers needlessly assign stuff to varialbes. Just making sure.
For security reasons. To make sure the variable did come from POSTing a form
and not from the URL.
> Finally, if you really want to use $HTTP_POST_VARS[] AND your'e
> running PHP 4.1*, consider using the superglobal $_POST[] instead.
--
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
/*
Nobody knows what goes between his cold toes and his warm ears.
-- Roy Harper
*/