Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53421 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 17494 invoked from network); 20 Jun 2011 16:10:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jun 2011 16:10:16 -0000 Authentication-Results: pb1.pair.com smtp.mail=johannes@schlueters.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=johannes@schlueters.de; sender-id=unknown Received-SPF: error (pb1.pair.com: domain schlueters.de from 217.114.211.66 cause and error) X-PHP-List-Original-Sender: johannes@schlueters.de X-Host-Fingerprint: 217.114.211.66 config.schlueters.de Received: from [217.114.211.66] ([217.114.211.66:33157] helo=config.schlueters.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FE/69-34681-7E07FFD4 for ; Mon, 20 Jun 2011 12:10:16 -0400 Received: from [192.168.2.230] (ppp-93-104-43-78.dynamic.mnet-online.de [93.104.43.78]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by config.schlueters.de (Postfix) with ESMTPSA id E171C744C9; Mon, 20 Jun 2011 18:10:12 +0200 (CEST) To: Robert Eisele Cc: Etienne Kneuss , Derick Rethans , internals@lists.php.net In-Reply-To: References: <1308584208.6296.9.camel@guybrush> Content-Type: text/plain; charset="UTF-8" Date: Mon, 20 Jun 2011 18:09:10 +0200 Message-ID: <1308586150.6296.13.camel@guybrush> Mime-Version: 1.0 X-Mailer: Evolution 2.30.2 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Negative string offsets From: johannes@schlueters.de (Johannes =?ISO-8859-1?Q?Schl=FCter?=) On Mon, 2011-06-20 at 17:49 +0200, Robert Eisele wrote: > I would not consider this for arrays and objects, too. If we had real > arrays, this would make sense but they are HT's and therewith it can also be > explained that -1 is an element and not the end of the chained list behind > the HT. Yes. So having this in the current form accepted means that $a[-1]; can have two meanings: 1) Get the last item (byte in a string) 2) Get item `-1` (in an array) Which are to different things. Currently we treat $a{$o} and $a[$o] as equal. My suggestion was to split this up to avoid the conflict from above. I didn't suggest adding support for $a[-1] as last element for arrays, I know quite well why this won't make sense. johannes > 2011/6/20 Johannes Schlüter > > > On Mon, 2011-06-20 at 16:31 +0200, Etienne Kneuss wrote: > > > >> Negative string offsets is a wish and also an implementation of my > > running > > > >> PHP version for long. It operates in the same fashion like substr() > > with > > > >> negative offsets, but avoids the function call and is much smarter if > > one > > > >> single character has to be extracted: > > > > > Do you mean ArrayObject? ArrayAccess is the interface. > > > Regardless, I don't believe it makes sense to change the semantics of > > > those indexes for arrays, since arrays can define negative indexes. > > > i.e. $a = array(-1 => "foo", 2 => "bar"); $a[-1] should really be > > > "foo", and not "bar". > > > > This clearly shows the inconsistency this brings. Maybe $var{$offset} > > should be clearly deprecated for arrays and $var[$offset] for strings as > > in PHP they work differently. > > > > johannes > > > > > >