# dropping curly braces

- Thread: https://externals.io/message/20143
- Original archive: https://news-web.php.net/php.internals/20143
- Started by Ford on 2005-11-18T12:58:26+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #20143 — Ford — 2005-11-18T12:58:26+00:00

URL: https://externals.io/message/20143#20143

> Andreas Korthaus wrote:
> 
> > […]
> 
> 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

---

## #20146 — Marian Kostadinov — 2005-11-18T13:27:26+00:00

URL: https://externals.io/message/20143#20146 · In reply to: #20143

+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.



> 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?
>
> > […]

---

## #20150 — Ron Korving — 2005-11-18T14:16:56+00:00

URL: https://externals.io/message/20143#20150 · In reply to: #20143

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.


> > […]
>
> 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

---

## #20159 — Hans Zaunere — 2005-11-18T15:41:31+00:00

URL: https://externals.io/message/20143#20159 · In reply to: #20143

Ford, Mike wrote on Friday, November 18, 2005 7:58 AM:
> 
> 
> > […]

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...

> > […]

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.

> > […]
you
> > […]
> 
> 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
