Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84034 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 33751 invoked from network); 27 Feb 2015 17:51:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Feb 2015 17:51:17 -0000 Authentication-Results: pb1.pair.com header.from=lester@lsces.co.uk; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=lester@lsces.co.uk; spf=permerror; 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:37558] helo=mail4.serversure.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F9/EE-32582-49EA0F45 for ; Fri, 27 Feb 2015 12:51:17 -0500 Received: (qmail 23163 invoked by uid 89); 27 Feb 2015 17:51:12 -0000 Received: by simscan 1.3.1 ppid: 23157, pid: 23160, t: 0.0821s 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 17:51:12 -0000 Message-ID: <54F0AE90.4020508@lsces.co.uk> Date: Fri, 27 Feb 2015 17:51:12 +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> 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 16:46, Damien Tournoud wrote: > You probably haven't read the examples that I pasted. If you think that it > makes sense to return an error code if the function is called with invalid > arguments, it should be done consistently. The current behavior is just an > absurdly inconsistent, it is really hard to find an argument in favor of > it, other than the argument in favor of backward compatibility. That some changes to the logic of substr have been made is a fact. Negative values were added to read back from the end of the string a function that has been played with over time, # It is NOT OK to start reading past the end of the string, no, no. Bad programmer. If there are no characters left ... the string is empty. # But it is OK to ask for a bigger slice than the length of the string. Yes ... length is the MOST it will return, if less are available then that is all you can get. # It is also OK to read past the begining of the string, why not. If the reading point does not cut characters then yes this is consistent. If the length requested was '2', then I would expect 'a' and false which I think was what the 'bug fix' for PHP5.2.2 was supposed to do, but it was reverted later in 5.2.7 # On the other hand, it is NOT OK to stop reading before the end of the string. Bad programmer. Take 2 characters off the string ... empty string. 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 ... -- 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