Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:90857 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30076 invoked from network); 23 Jan 2016 21:02:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Jan 2016 21:02:23 -0000 X-Host-Fingerprint: 176.248.189.98 unknown Received: from [176.248.189.98] ([176.248.189.98:26476] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 05/16-03822-D5AE3A65 for ; Sat, 23 Jan 2016 16:02:22 -0500 Message-ID: <05.16.03822.D5AE3A65@pb1.pair.com> To: internals@lists.php.net References: <56A3A01F.1020500@php.net> Date: Sat, 23 Jan 2016 21:02:18 +0000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:42.0) Gecko/20100101 Firefox/42.0 SeaMonkey/2.39 MIME-Version: 1.0 In-Reply-To: <56A3A01F.1020500@php.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Posted-By: 176.248.189.98 Subject: Re: [RFC] Generalize support of negative string offsets From: ajf@ajf.me (Andrea Faulds) Hi François, François Laupretre wrote: > Starting discussion about https://wiki.php.net/rfc/negative-string-offsets > > Please read and comment. I like this RFC. Being able to use negative offsets helps code readability, but it not being universally supported is annoying. I like that this brings more consistency. I particularly like that this is supported for string indexing with the []/{} operator. At present a negative offset is interpreted as being the maximum string length plus that offset, so $str[-1] is equivalent to $str[(2**64 - 1) - 1]. In practice, this means you will get an empty string and an "Uninitialized string offset:" E_NOTICE. It's not useful except for extremely large strings and so I suspect that behaviour comes from an implementation detail (naïve signed-to-unsigned integer conversion). What you're proposing is to have the negative offset be interpreted as an offset from the end of the string, as the built-in functions do. This is more useful, but it's a change of behaviour from the present one, and thus a backwards-compatibility break, even if it's unlikely to affect real-world code. So, you might wish to mention that. Also, I think the RFC would be more accessible if you included some examples of where to use negative offsets. That would give readers an at-a-glance view of what the RFC changes. Anyway, I like what you're doing here. Thanks for the proposal! -- Andrea Faulds https://ajf.me/