Hi Rasmus!

Rasmus Lerdorf wrote:

Very few people converted to using {} so the argument about reading old code doesn't really hold.

I can't belive that most of the code today is based on <=PHP3 code. I'm not talking about such "PHP3 based" code. I'm talking about code, you wrote 1 year ago and did not touch for 10 months. Or code you have to debug which someone else wrote.

If you go and grep through all the public code out there, pretty much none of it uses {} for character offsets.

That's the problem - also grep does not know if [] is used for arrays or stings. That's the same for programmers, it's often not easy to conclude from context - that's my point.

Having two syntaxes for the same thing makes no sense, and getting rid of [] would break all sorts of stuff.

Do you think it would break more stuff than getting rid of {}? How do you know? grep definitely can't help you here.

The original reason for the {} was a technical one to simplify the parser, but the landscape has changed and that reason no longer exists.

But [] has been marked deprecated in favour of {} for 5 years now. Netcraft finds 10 times more php-domains today than 5 years ago.

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.

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? Most non-PHP people I have asked have answered [].

Hm, most people I can think of would seach the manual for a string function, and not even think of syntax like {} or []. Some day I found {} syntax in the manual, saw that I could use [] too, but which is deprecated. {} was a very straightforward syntax in my eyes (at that time). If you want to use PHP, you have to know the manual anyway, so I don't think this is a big advantage.

Removing the obvious syntax just doesn't make any sense. The other place {} is used outside of control blocks is in quoted strings where "{$foo{1}}" is much uglier than "{$foo[1]}".

Yes that's a disadvantage. But one of my most important goals when writing scripts (in a major project) is to reduce complexity and make scripts as easy to understand as possible. And PHP makes a good job here. But I think the {} -> [] change will reduce readability of scripts, because both programmers and "grep" can't differ arrays from strings using the [] syntax anymore.

However, thanks a lot for your time/explanation!


best regards
Andreas

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to