Is there anything wrong with having a convention for character access of strings? Most PHP programmers see {} as string access and [] as array access - sure, they might be functionally identical, but its the convention which is important.
Jevon
-------Original Message-------
From: Rasmus Lerdorf rasmus@lerdorf.com
Subject: Re: [PHP-DEV] dropping curly braces
Sent: 17 Nov '05 12:11Andreas Korthaus wrote:
As far a code readability and obviousness goes, I doubt anybody would
guess their way to the $str{5} syntax.But you know without understanding of any context, that it's the 6th
character of the string "$str". When you see $var[5], it could be the
6th character of a string, or an element of an array... and what about
the value? You can't be sure that it's a string with length 1, it also
could be another array, an object, a string with length 4711...That increases complexity and decreases readability.
Your argument falls apart there. Try it:
$a = array("ab","cd","ef");
echo $a{2};Guess what that prints? {} has nothing to do with strings. They are
100% equivalent to [] and as such add nothing to clarity.-Rasmus
How do you know this? Have you conducted polls?
-Andrei
Is there anything wrong with having a convention for character
access of strings? Most PHP programmers see {} as string access and
[] as array access - sure, they might be functionally identical,
but its the convention which is important.