On 27/02/15 20:28, Damien Tournoud wrote: > Hi Lester, > > On Fri, Feb 27, 2015 at 6:51 PM, Lester Caine <les...@lsces.co.uk > <mailto:les...@lsces.co.uk>> wrote: > > This may not be what YOU want substr to do and it would perhaps be > useful to ADD additional checks so that 'false' is returned when it > can't created a string because of the 'invalid arguments', but type > hints makes no difference to part of the jigsaw. What happens is exactly > what one would expect ... nothing left in the string -> an empty string. > Having then to check every time for a '0' string length got shortened to > simply being able to check 'is there a string' yes/no, and if no you can > do something else. There is nothing inconsistent ... > > Please, read the examples again, the current behavior is nothing but > inconsistent: > > substr("a", 1) => FALSE > substr("a", -300) => ""
? That was the case prior to PHP5.2.1 The fixes in 5.2.2 were not commonly accepted but give false for both, but 5.2.7 and later give false and "a" which is what was the preferred result at the time. Unless we are seeing something different, I'm only seeing "a" or false for a current output of all your examples. > But anyway, that's not even the point. The point is that return values > that "worked" in a world of transparent type-jungling will not work in a > world of stricter typing checks. Which means that we need: > > (1) To accept that for now casting FALSE to the empty string is the > right thing to do; > > until / unless: > > (2) We fixed all the common functions in the standard library so that > they stop returning inconsistent types, in particular in the cases where > it should not even be a debate what is the right thing to do (for > substr, if the arguments point to an empty slice, return the empty string). That side I totally agree with. The 'fixes' posted so far such as adding (string) or replacing false by 0 should be enough to prevent adoption, and personally I find the strict option just as problematic. -- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php