John Porter wrote:

> Chaim Frenkel wrote:
> >
> > Removing -1 as a valid result, could be a breakage (if someone is
> > doing something weird with a negative result)
>
> What, like using it as an index into a substr?
> Bad Code is its own reward, my friend.
>
> >       $foo = "flabergasted";
> >       substr($foo, index($foo, 'abc'), 20);   # Returns undef
>
> One should never do this, regardless of what index() returns on
> failure.  Now, if index() threw an exception on failture, you'd
> be o.k.  But I don't think we want that...

That's exactly why it would be nice if index _did_ throw an exception on
failure, then you could write code this way, and catch the failures
without needing to check return values for the error code case before
proceeding with the real case.

--
Glenn
=====
There  are two kinds of people, those
who finish  what they start,  and  so
on...                 -- Robert Byrne



_____NetZero Free Internet Access and Email______
   http://www.netzero.net/download/index.html

Reply via email to