Re: [RFC] Generalize support of negative string offsets
| From: | Andrea Faulds | Date: | Sat, 23 Jan 2016 21:10:29 +0000 |
| Subject: | Re: [RFC] Generalize support of negative string offsets | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-90858@lists.php.net to get a copy of this message | ||
Hi again,
Andrea Faulds wrote:
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.Er, ignore what I just said. Negative string offsets are actually special-cased and always produce an "Unitialized string offset" or "Invalid string offset" notice. So our current behaviour is in fact completely useless, not just mostly. :) Sorry about that. -- Andrea Faulds https://ajf.me/