RE: dropping curly braces

php.internals

Ford, Mike [LSS]

20 years ago
On 17 November 2005 21:42, Rasmus Lerdorf wrote:
> Andreas Korthaus wrote: > > > Can someone tell me the reason for this decision? > > Very few people converted to using {} so the argument about > reading old > code doesn't really hold. If you go and grep through all the public > code out there, pretty much none of it uses {} for character offsets. > And internally there is absolutely no difference between {} and [].
So all of those who belived the "[] for string access is deprecated" line (or simply prefer the visual differentiation) and have 10s of thousands of lines of code with liberal use of $string{} are going to have to spend ages fixing that up?
> Having two syntaxes for the same thing makes no sense,
I don't buy this -- having two ways of doing certain things is one feature that makes PHP so great -- it increases the user base who find it easy to use, as they can pick the method that makes most sense to them. I love the {} syntax, so let me use it. You don't -- fine, don't use it. (I won't convert to [] -- I'll go for substr(..,..,1) instead). Another example: I hate proliferating {} for control structures and use exclusively the if (): ... endif; form -- fine, let me use it; your preference may be otherwise, but that's fine too. In the end, each of us gets the PHP syntax we find easiest to use, without denying the other his preference. What's so wrong with that?
> As far a code readability and obviousness goes, I doubt anybody would > guess their way to the $str{5} syntax. If you were new to > PHP and you > were going to try to guess how you would get a character offset in a > string, what would your first guess be?
Well, it wouldn't be [] because I'd guess that's for array access as in other languages. I probably wouldn't guess at all, but look it up, and be very happy to find it was {}. I remember being very, very surprised to find [] doing double duty, and glad that {} existed as an alternative. Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: m.ford@leedsmet.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm

Marian Kostadinov

20 years ago
+1 for keeping {} sintax in PHP6. It's not fair for all those people who endeavoured to write a good PHP code and followed the recommendations for it. And why should this feature be removed while in the mean time PHP developers are desparately keeping some very very old stuff for BC reasons? This is IMO an inconsistent behaviour. On 18/11/05, Ford, Mike <M.Ford@leedsmet.ac.uk> wrote:

Ron Korving

20 years ago
I hear a lot of opinions here on the curly braces issue, and while I don't use them, they're not in the way. I'd say let's keep them in.
> > As far a code readability and obviousness goes, I doubt anybody would > > guess their way to the $str{5} syntax. If you were new to > > PHP and you > > were going to try to guess how you would get a character offset in a > > string, what would your first guess be? > > Well, it wouldn't be [] because I'd guess that's for array access as in > other > languages. I probably wouldn't guess at all, but look it up, and be very > happy to find it was {}. I remember being very, very surprised to find [] > doing double duty, and glad that {} existed as an alternative.
You obviously have no C(++) experience. People with the C-background consider strings to be arrays of characters, and therefor it makes perfect sense to use [], just like it makes sense to use [] for strings in C. I don't see a problem with {} however, and see no reason why it should be removed. I don't find it disturbing when I have to read someone's code containing {}, so why remove it and make a lot of people angry? I don't see the improvement except that certain warm and fuzzy feeling... Ron

Hans Zaunere

20 years ago
Ford, Mike wrote on Friday, November 18, 2005 7:58 AM:
> On 17 November 2005 21:42, Rasmus Lerdorf wrote: > > > Andreas Korthaus wrote: > > > > > Can someone tell me the reason for this decision? > > > > Very few people converted to using {} so the argument about reading old > > code doesn't really hold. If you go and grep through all the public > > code out there, pretty much none of it uses {} for character > > offsets. And internally there is absolutely no difference between > > {} and [].
And most public code still uses hacks for register_globals, is insecure and poorly written.
> So all of those who belived the "[] for string access is deprecated" > line (or simply prefer the visual differentiation) and have 10s of > thousands of lines of code with liberal use of $string{} are going to > have to spend ages fixing that up?
Sounds like they got us good! No more listening to documentation for us...
> > Having two syntaxes for the same thing makes no sense,
And neither does arbitrarily removing one syntax; especially when that syntax has been the recommended way of referencing characters in strings for years.
> I don't buy this -- having two ways of doing certain things is one > feature that makes PHP so great -- it increases the user base who > find it easy to use, as they can pick the method that makes most > sense to them. I love the {} syntax, so let me use it. You don't -- > fine, don't use it. (I won't convert to [] -- I'll go for > substr(..,..,1) instead). Another example: I hate proliferating {} > for control structures and use exclusively the if (): ... endif; form > -- fine, let me use it; your preference may be otherwise, but that's > fine too. In the end, each of us gets the PHP syntax we find easiest > to use, without denying the other his preference. What's so wrong > with that?
And with so much work to maintain backwards compatibility in the past, why do we need this change now? While we're changing things, let's standardize function parameter ordering.
> > As far a code readability and obviousness goes, I doubt anybody > > would guess their way to the $str{5} syntax. If you were new to PHP and
you
> > were going to try to guess how you would get a character offset in a > > string, what would your first guess be? > > Well, it wouldn't be [] because I'd guess that's for array access as > in other languages. I probably wouldn't guess at all, but look it > up, and be very happy to find it was {}. I remember being very, very > surprised to find [] doing double duty, and glad that {} existed as > an alternative.
Yup - if anything, let's remove [] as string access - then again, if it ain't broke, why try to fix it? --- Hans Zaunere / President / New York PHP www.nyphp.org / www.nyphp.com