Re: deprecation status of $str{42} versus $str[42]

From: Date: Sat, 14 Jun 2008 16:14:53 +0000
Subject: Re: deprecation status of $str{42} versus $str[42]
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-38220@lists.php.net to get a copy of this message
Hello, On Tue, Jun 10, 2008 at 9:11 PM, Andi Gutmans <andi@zend.com> wrote: > Hi, > > $str{} was considered a best practice for a while so as you can see via > Google Code Search it's been used quite a bit. > I take the blame for introducing it with the intention to not only > create a better separation between arrays and string offsets but by also > then allowing for a cleaner implementation for string offsets. > Unfortunately I never delivered that cleaner implementation esp. as > there didn't seem a huge benefit > > I don't have strong feelings either way esp. as moving from $str{} to > $str[] is scriptable but given that so many people have used it and > there are benefits to separating the two (it also resolves an ambiguity) > I'd like to put another option out there which is to try and see if we > can actually follow through on original intentions of also delivering > technical benefit in addition to the syntax separation. I personally have always used {} for string offsets because it just felt right. [] seems like it is for arrays, for me, using it on strings makes me feel dirty. Could we maybe visit some of the ideas you have had with {} syntax offering some benefit? That I do not completely understand and would be nice to know what you mean. Maybe something like built in substr? since it wouldn't break existing use of {}, tough thing is the ambiguity between {1} regular and {1} substr, dunno: $str = "abcdef"; $result = $str{1}; // returns b, but substr would be something like bcdef $result = $str{1, 2} // returns bc, this we know what to return for sure $result = $str{1,} // maybe to make up for lack of {1} returning remaining portion, its a little ugly almost feels like a syntax error Just trying to figure out how you could have technical benefit with it, maybe you just meant performance optimization or something. -Chris

« previous php.internals (#38220) next »