Re: [RFC] Generalize support of negative string offsets

From: Date: Sat, 23 Jan 2016 21:02:18 +0000
Subject: Re: [RFC] Generalize support of negative string offsets
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-90857@lists.php.net to get a copy of this message
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/

« previous php.internals (#90857) next »