Hello Rasmus,
Sunday, October 31, 2004, 11:27:40 PM, you wrote:
On Sun, 31 Oct 2004, moshe doron wrote:
where the problem about 'taking it ever further'? I'm +1 for {-1} and more +1 for {-4,2} python likeness.
That starts getting confusing. I assume that translates to the 3rd and 4th chars from the end of the string. And, to verify that I went and looked it up and it turns out that's not the case in Python. They use [start_index:end_index] so [-4:2] would be the 4th char from the end until
the 2nd char in the string, so for a 6 char string or longer that would return nothing, but worse, my initial guess at what it did was wrong. I don't like features where my first guess at what something does is wrong.
Same from here. If we do it it should behave like a short form of substr.
{} returns a single character a certain offset from 0, I don't see any reason to implement any of substr's advanced features. $a{3} returns the 4th character. $a{-3} would return the 4th character from the end. Simple, end of story. It would reduce the errors I inevitably get whenever using a complex feature like substr(). The three choices:
1) substr($a, strlen($a) - 1); 2) $a{strlen($a) - 1} 3) $a{-1}
It's pretty obvious that the 3rd choice lowers the potential for all kinds of bugs (mistypign, wrong parameter name, incorrect parameter placement), and is much more readable. For those who already know how {} works in PHP, it's also obvious what it does at the first look without any speculation.
Greg
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php