Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:13628 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91137 invoked by uid 1010); 30 Oct 2004 06:20:15 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 91057 invoked from network); 30 Oct 2004 06:20:14 -0000 Received: from unknown (HELO prohost.org) (216.126.86.27) by pb1.pair.com with SMTP; 30 Oct 2004 06:20:14 -0000 Received: (qmail 14796 invoked from network); 30 Oct 2004 06:20:13 -0000 Received: from cpe0050bad46dce-cm000f9f7d6664.cpe.net.cable.rogers.com (HELO ?192.168.1.101?) (@69.196.31.138) by prohost.org with SMTP; 30 Oct 2004 06:20:13 -0000 Message-ID: <41833298.6000906@prohost.org> Date: Sat, 30 Oct 2004 02:20:08 -0400 User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Alan Knowles , internals@lists.php.net References: <418294D9.4070700@prohost.org> <4182E553.20801@akbkhome.com> In-Reply-To: <4182E553.20801@akbkhome.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] Negative string offset support From: ilia@prohost.org (Ilia Alshanetsky) While you are correct that invalid offset in a string will produce an error message. This error message is E_NOTICE, given that our default INI error reporting level won't display those it's arguable that very few people will see them and consequently do something about it. > echo $a{strlen($a)-1}; ? is that really that bad. It is not that bad, but it could be better. Basic tests I've ran show that using a strlen() is 30-40% slower and substr() is 20-25% slower then $a{-1}. Ilia Alan Knowles wrote: > > I do worry that at present > $a = "a string"; > $p = 0 > while( $p < strlen($p) ) > .. do stuff that could do $p-- or $p++ .... > echo $a{$p}; > } > > at present that would produce a nice error if you went < 0.. easy to > spot.. - if -ve was supported it could do unexpected stuff.. > > Regards > Alan > > Ilia Alshanetsky wrote: > >> I am wondering what are people's opinions on adding support for >> negative string offsets that could be used to access data from the end >> of a string. >> >> Ex. $a = "123"; echo $a[-1]; // would print 3 >> >> I don't think we should do this for arrays, since -1 and similar are >> valid array keys, which means adding this support for arrays would >> break BC. >> >> Ilia >> >