Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84056 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 12730 invoked from network); 27 Feb 2015 23:04:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Feb 2015 23:04:14 -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:49162] helo=mail4.serversure.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 93/DD-32582-CE7F0F45 for ; Fri, 27 Feb 2015 18:04:13 -0500 Received: (qmail 22813 invoked by uid 89); 27 Feb 2015 23:04:10 -0000 Received: by simscan 1.3.1 ppid: 22805, pid: 22809, t: 0.0904s 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 23:04:09 -0000 Message-ID: <54F0F7E9.20003@lsces.co.uk> Date: Fri, 27 Feb 2015 23:04:09 +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> <54F0D94D.3070501@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 21:14, Damien Tournoud wrote: > Hi Lester, > > On Fri, Feb 27, 2015 at 9:53 PM, Lester Caine > wrote: > > > 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. > > I meant "a", but you are right, it's a bit less inconsistent than I > thought. The current behavior could be defined as "if the resulting > slice is so that (start index <= end index) and (either start index or > end index is in bound) return the slice, else return FALSE", which is > not very useful but not so bad anyway. > > The only real annoyance is that the check is strict on the right bound, > so that: > > substr("abcd", 5) => FALSE > > while: > > substr("abcd", -10, -4) => "" This is the where the -ve logic stuff was changed. If you try -5 rather than -4 things swap around versions wise. The 'problem' is where the actual buffer length goes to 0 and then -ve. There still seem to be a few edge cases that are not correctly caught, but then currently "" and false default to false anyway so there is ONLY a problem if one DOES remove the weak casting. > That explains one of the E_DEPRECATED triggered by Drupal 7, because > when you want to remove a prefix from a string, you often do: > > if (substr($str, 0, strlen($prefix)) { > $str = substr($str, strlen($prefix)) > } > > But this currently returns FALSE when $str == $prefix. > (Obviously, the most useful behavior would be to return a string in all > cases, like for example, Python.) If you only want strings then OK, but in that case how would you rework the drupal problem anyway? Although I'd not start from that if statement anyway if there is a chance that the $str and $prefix ARE the same string? The current if statement is what is wrong not the second substr. if ( strlen($str) > strlen($prefix) ) { $str = substr($str, strlen($prefix)) } else { // nothing left } But how do you know that the string contains the prefix? Yes the legacy code base needs tidying up and is full of bugs, but we often just need to tidy up the logic ... -- 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