Re: Negative string offsets

From: Date: Thu, 17 Apr 2014 14:18:03 +0000
Subject: Re: Negative string offsets
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-73720@lists.php.net to get a copy of this message
Hi, On Thu, Apr 17, 2014 at 5:13 PM, Johannes Schlüter <johannes@schlueters.de> wrote: > Hi, > > On Thu, 2014-04-17 at 13:01 +0100, Leigh wrote: >> What are peoples thoughts on allowing negative string offsets, that return >> characters from the end of a string. > > I'm +/-0 on this. But mind: Current form makes it simpler to find bugs > when miscalculating the offset. Allowing negative offsets gives harder > to debug results. Additionally I wonder how often this is actually > needed, thus justifying to change the language rules. > > johannes For example, every time you need to check for a filename extension, last segment of a path, etc. When I need that, I always endup with substr(), strrchr() or explode(), end() ... both are suboptimal. Cheers, Andrey.

« previous php.internals (#73720) next »