Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84051 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88148 invoked from network); 27 Feb 2015 21:14:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Feb 2015 21:14:58 -0000 Authentication-Results: pb1.pair.com header.from=damz@damz.org; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=damz@damz.org; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain damz.org designates 74.125.82.176 as permitted sender) X-PHP-List-Original-Sender: damz@damz.org X-Host-Fingerprint: 74.125.82.176 mail-we0-f176.google.com Received: from [74.125.82.176] ([74.125.82.176:42073] helo=mail-we0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2C/69-32582-15ED0F45 for ; Fri, 27 Feb 2015 16:14:58 -0500 Received: by wesw62 with SMTP id w62so22739303wes.9 for ; Fri, 27 Feb 2015 13:14:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=damz.org; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=E0tpzXsqyVceAsnT9ryvv1ovX8ncf4rHMIypEDJUWlc=; b=fUPWfSn92N4MdAG7pd70T/UQW178WNSmR27NUsiBgRukOpOX1HRVXEVZ3th7SRZKqv YyxFo4RKNIG+GtfKwedUo4/134z2dBDj9lHdaRO8Sx++enAipRM72mQ8zMm2S7pCf229 1ZqTdK/QNQG8UP01nhn2mkT3pkBQQVig4LPrg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=E0tpzXsqyVceAsnT9ryvv1ovX8ncf4rHMIypEDJUWlc=; b=J382MF3B8EwvdA6yUy8jSIBqvj7k6HQxinFA3VGJ56puZazCF4SVzIfaM7sS1lnSqU Ife9u1A9pI9h1gAfYM16BSek44vQ6wm69iq+tHHXOoRDq+qa+QwI78nw1MmKzSmk3Pjz oXgIj+z1+wzQ7em0xxFLDNBWFli131bCADWhV6GT7K78zCswzb7Axp7yT2BRLrRzmGme HsERE4UR08rHt1DFtBPehccodwdkwAvN//9mvYV5MqeOaB18edsZz1zld+Z7skvrMSSE TfiywupsTpIpGmh3ZMzKKb2ms4oj+hfFa7ODAB4/InJD4G9o1qvuzEpXIEqpJnZ5uqjs hyVQ== X-Gm-Message-State: ALoCoQnsDh8aMSVJxp2CEcKPgSWbGrQSztlAFQwRzdxB7d+FJdgLFt3Z8xH43Z9uIlWdUBcfjvmR MIME-Version: 1.0 X-Received: by 10.194.21.137 with SMTP id v9mr31331197wje.140.1425071695006; Fri, 27 Feb 2015 13:14:55 -0800 (PST) Received: by 10.28.181.131 with HTTP; Fri, 27 Feb 2015 13:14:54 -0800 (PST) X-Originating-IP: [78.126.234.166] In-Reply-To: <54F0D94D.3070501@lsces.co.uk> References: <4ED7146272E04A47B986ED49E771E347D3111ACD71@Ikarus.ameusgmbh.intern> <54F0AE90.4020508@lsces.co.uk> <54F0D94D.3070501@lsces.co.uk> Date: Fri, 27 Feb 2015 22:14:54 +0100 Message-ID: To: Lester Caine Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=047d7b5d28342923a80510185c7d Subject: Re: [PHP-DEV] Coercive STH - some real world tests and updated RFC From: damz@damz.org (Damien Tournoud) --047d7b5d28342923a80510185c7d Content-Type: text/plain; charset=UTF-8 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) => "" 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.) Damien --047d7b5d28342923a80510185c7d--