Re: Coercive STH - some real world tests and updated RFC

From: Date: Fri, 27 Feb 2015 20:28:38 +0000
Subject: Re: Coercive STH - some real world tests and updated RFC
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-84043@lists.php.net to get a copy of this message
Hi Lester, On Fri, Feb 27, 2015 at 6:51 PM, Lester Caine <lester@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) => "" 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). Damien

« previous php.internals (#84043) next »