Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84047 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 79631 invoked from network); 27 Feb 2015 20:53:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Feb 2015 20:53:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=lester@lsces.co.uk; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=lester@lsces.co.uk; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lsces.co.uk from 217.147.176.214 cause and error) X-PHP-List-Original-Sender: lester@lsces.co.uk X-Host-Fingerprint: 217.147.176.214 mail4-2.serversure.net Linux 2.6 Received: from [217.147.176.214] ([217.147.176.214:36245] helo=mail4.serversure.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 47/A7-32582-059D0F45 for ; Fri, 27 Feb 2015 15:53:36 -0500 Received: (qmail 12305 invoked by uid 89); 27 Feb 2015 20:53:33 -0000 Received: by simscan 1.3.1 ppid: 12298, pid: 12301, t: 0.0909s scanners: attach: 1.3.1 clamav: 0.96/m:52/d:10677 Received: from unknown (HELO ?10.0.0.8?) (lester@rainbowdigitalmedia.org.uk@86.189.147.37) by mail4.serversure.net with ESMTPA; 27 Feb 2015 20:53:33 -0000 Message-ID: <54F0D94D.3070501@lsces.co.uk> Date: Fri, 27 Feb 2015 20:53:33 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: "internals@lists.php.net" References: <4ED7146272E04A47B986ED49E771E347D3111ACD71@Ikarus.ameusgmbh.intern> <54F0AE90.4020508@lsces.co.uk> In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Coercive STH - some real world tests and updated RFC From: lester@lsces.co.uk (Lester Caine) On 27/02/15 20:28, Damien Tournoud wrote: > Hi Lester, > > On Fri, Feb 27, 2015 at 6:51 PM, Lester Caine > 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