|
Posted by Erwin Moller on 03/14/06 15:09
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] :-)";
> ?>
Navigation:
[Reply to this message]
|