Re: Negative string offsets

From: Date: Thu, 17 Apr 2014 15:33:22 +0000
Subject: Re: Negative string offsets
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-73724@lists.php.net to get a copy of this message
On Thu, Apr 17, 2014 at 08:25:34AM -0700, Rasmus Lerdorf wrote: > Yeah, it wouldn't make any sense unless it supported ranges. Something like: > > if($filename[-4,4] === '.ext') ... > > although, I don't see how that is better than: > > if(substr($filename,-4) === '.ext') ... > > The latter is much clearer. Clarity depends on what you are used to. Once that was in the language and had been used a few times - you would just read it. Looking at your example of rangs (or slices) checking the last bit of a string would be nicer if you could omit the length to do exactly what you example above does: if($filename[-4,] === '.ext') ... -- Alain Williams Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php #include <std_disclaimer.h>

« previous php.internals (#73724) next »