Re: Re: Negative string offset support

From: Date: Mon, 01 Nov 2004 15:19:45 +0000
Subject: Re: Re: Negative string offset support
References: 1 2 3 4 5 6 7 8 9 10 11 12 13  Groups: php.internals 
Request: Send a blank email to internals+get-13668@lists.php.net to get a copy of this message
Substr_replace() for the purpose of changing one char is like using a tank for a fly swatter, it may work but it is extremely inefficient. Ilia Andrey Hristov wrote:
just to mention that there is substr_replace() php -r '$a="abc"; var_dump(substr_replace($a, "d", -1));' IMO at least there is no need for range like $a{-4:2} Andrey Ilia Alshanetsky wrote:
IMO {-1} syntax is not only faster but simpler to use then the equivalent substr() (for read) or $a[strlen($a) - 1] (for write). While my reasons are primarily performance based, I think that most people would find the {-1} simpler to use as well. Ilia Sterling Hughes wrote:
i hope not. this should be about what's cool for developers, the speed increase is not a compelling reason.. the debate is "does this make code easier to read/write/maintain?" I think it doesn't, and therefore am against it. -sterling On Mon, 1 Nov 2004 03:04:45 +0100, Marcus Boerger <helly@php.net> wrote:
Hello Wez, well it would. However 5.1 aims to be a major speed improvement and that's what the idea is about. best regards marcus Monday, November 1, 2004, 2:29:46 AM, you wrote:
Doesn't substr($a, -1) work ?
--Wez.
On Sun, 31 Oct 2004 17:45:03 -0500, Greg Beaver <cellog@php.net> wrote:
It would reduce the errors I inevitably get whenever using a complex feature like substr(). The three choices: 1) substr($a, strlen($a) - 1); 2) $a{strlen($a) - 1} 3) $a{-1} It's pretty obvious that the 3rd choice lowers the potential for all kinds of bugs (mistypign, wrong parameter name, incorrect parameter placement), and is much more readable. For those who already know how {} works in PHP, it's also obvious what it does at the first look without any speculation.
-- Best regards,
Marcus                            mailto:helly@php.net
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.internals (#13668) next »