Re: $request problem
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: $request problem

From: Erwin Moller <since_humans_read_this_I_am_spammed_too_much@spamyourself.com>
Date: Tue Mar 14 2006 - 14:09:41 CET

ColdShine wrote:

<snip>

I liked this discussion, and it cleared a few thing up I never understood,
and thus simply avoided in all my code.
Your examples are a nice summary. :-)

I couldn't resist myself to give some comment.

>
> Here's a quick roundup, if you (or anyone f'wing this thread) still are
> wondering WHAT is meant WHEN:
>
> <?php
> $arr = array('key' => 'foo');
> define('key', 'another');
>
> echo $arr[key]; // undefined index ('another')
> echo $arr['key']; // foo
> echo '$arr[key]'; // $arr[key]
> echo "$arr[key]"; // foo

Personally I think that it is a big mistake of PHP to let this construct
slip. :-/
Why try to be nice and 'correct' this internally to
$arr["key"] ??
Why not to defined key?
Sounds like a great source of bugs to me.

Why oh why not just produce an error?

These constructs are excactly why I walked away from Perl some years ago.
;-)

Another thing: Try to be nice to yourself and fellowprogrammers, and just
jump out of the string and concatenate what you need.

What's wrong with:
$result = "bla".$arr[key]." and of course: ".$arr["key"];

Why obfuscate code with complex parameters inside (double) quotes?
What is the point? Outsmart fellow programmers? If so: go Perl. ;-)

I think it is just unneccessary, and I never came across a situation where
it is actually needed...

Well, just my 2 cents.
And thanks for the examples.
I finally got it, but will surely never use it. :-)

Regards,
Erwin Moller

> echo "$arr['key']"; // parse error
> echo "{$arr[key]}"; // undefined index ('another')
> echo "{$arr['key']}"; // foo
> ?>
>
> This should rule out any misunderstandings.
>
> Btw,
> <?php
> $arr = array('c' => 'Cheers', 'f' => 'F**k off');
> define('c', 'f');
>
> echo "$arr[c] :-)";
> ?>
Received on Mon May 1 02:33:14 2006