Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:13668 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35039 invoked by uid 1010); 1 Nov 2004 15:20:53 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 30282 invoked from network); 1 Nov 2004 15:19:50 -0000 Received: from unknown (HELO prohost.org) (216.126.86.27) by pb1.pair.com with SMTP; 1 Nov 2004 15:19:50 -0000 Received: (qmail 9443 invoked from network); 1 Nov 2004 15:19:49 -0000 Received: from cpe0050bad46dce-cm000f9f7d6664.cpe.net.cable.rogers.com (HELO ?192.168.1.101?) (@69.196.31.138) by prohost.org with SMTP; 1 Nov 2004 15:19:49 -0000 Message-ID: <41865411.2060905@prohost.org> Date: Mon, 01 Nov 2004 10:19:45 -0500 User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Andrey Hristov CC: internals@lists.php.net References: <418294D9.4070700@prohost.org> <20041029193421.9557.qmail@pb1.pair.com> <5.1.0.14.2.20041029162045.0439b9c0@localhost> <20041031093753.74166.qmail@pb1.pair.com> <42285846.20041031233522@marcus-boerger.de> <41856AEF.4060501@php.net> <4e89b426041031172932ada70f@mail.gmail.com> <1152524831.20041101030445@marcus-boerger.de> <24e5f3b7041031220372d44413@mail.gmail.com> <41864BCA.5050701@prohost.org> <41865046.6040501@hristov.com> In-Reply-To: <41865046.6040501@hristov.com> X-Enigmail-Version: 0.86.1.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: Negative string offset support From: ilia@prohost.org (Ilia Alshanetsky) 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 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 >>>>> 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 >>>> >>>> >>> >>> >> >