Re: [Zend Engine 2] substr changes
| From: | Jeroen van Wolffelaar | Date: | Fri, 29 Jun 2001 10:00:44 +0000 |
| Subject: | Re: [Zend Engine 2] substr changes | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-58408@lists.php.net to get a copy of this message | ||
> > Yes, of course. But in a loop when you use for ($i=-3; $i<=0; $i--)...
I've
> > had this twice, I needed to make special case for the last possibility.
>
> This works fine: $i will contain, -3, -2, -1 and 0 (and not -0), but
> indeed I agree that substr ('str', 0, 0) should return this: 'str'. This
> change can be easily made in the current sources. If nobody objects, I'll
> change it.
This is IMO 'van de regen in de drup', i.e. making it worse... The kind of
loop I mentioned isn't as current as a loop like this:
for ($i=5;$i>=0;$i--)
substr('abcdef',0,$i);
wich your proposed change, you get:
(i=5) abcde
4 abcd
3 abc
2 ab
1 a
0 abcdef !
This has to do with the fact that 0 ==== -0 (4 ='s, it's really identical),
and that you can loop to 0 in two ways, which have completely, incompatible
meaning.
I think that if it is changed, you'll break quite some scripts... the
problem isn't in the current implementation, it's in the idea behind letting
negative values have a special meaning.
By the way, IMO the negative values with substr rate higher on WTF than
{left,length[,right]}, though it may seem different because you're used to
substr().
> regards,
> Derick
Jeroen