|
Posted by ColdShine on 11/18/95 11:42
Erwin Moller in news:4416c095$0$11067$e4fe514c@news.xs4all.nl wrote:
> 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. :-)
>
> 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"] ??
That's not a "correction", it's just... its behavior :)
> Why not to defined key?
> Sounds like a great source of bugs to me.
>
> Why oh why not just produce an error?
>
> 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. :-)
You're welcome, but... why stick to not using a language feature?
Look at this multiple string concatenation:
$s = $a['first'] . '#' . $a['second'] . '(' . $a['third'] . ')';
Becomes:
$s = "$a[first]#$a[second]($a[third])";
I found the latter syntax to be much clearer to read. And I suspect it's
faster to execute too, since it probably saves some string concatenations
(thus being less memory-intensive).
And, as this syntax is clearly a short-hand to the more common "standard"
syntax, why should constants be preferred over string keys, with string keys
being much more common than constant keys?
You can find the official samples here, if you like:
http://www.php.net/manual/en/language.types.string.php#AEN3054
If there's few people extensively using this syntax, it maybe due to the
page it's documented into being too lengthy...
--
ColdShine
"Experience is a hard teacher: she gives the test first, the lesson
afterwards." - Vernon Sanders law
Navigation:
[Reply to this message]
|