Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53422 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22208 invoked from network); 20 Jun 2011 16:27:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jun 2011 16:27:52 -0000 Authentication-Results: pb1.pair.com smtp.mail=robert@xarg.org; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=robert@xarg.org; sender-id=unknown Received-SPF: error (pb1.pair.com: domain xarg.org from 209.85.220.170 cause and error) X-PHP-List-Original-Sender: robert@xarg.org X-Host-Fingerprint: 209.85.220.170 mail-vx0-f170.google.com Received: from [209.85.220.170] ([209.85.220.170:43345] helo=mail-vx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4E/5A-34681-7057FFD4 for ; Mon, 20 Jun 2011 12:27:52 -0400 Received: by vxi39 with SMTP id 39so1086530vxi.29 for ; Mon, 20 Jun 2011 09:27:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.67.135 with SMTP id n7mr1287501vdt.246.1308587268289; Mon, 20 Jun 2011 09:27:48 -0700 (PDT) Received: by 10.220.45.196 with HTTP; Mon, 20 Jun 2011 09:27:48 -0700 (PDT) X-Originating-IP: [92.225.216.141] In-Reply-To: <1308586150.6296.13.camel@guybrush> References: <1308584208.6296.9.camel@guybrush> <1308586150.6296.13.camel@guybrush> Date: Mon, 20 Jun 2011 18:27:48 +0200 Message-ID: To: =?ISO-8859-1?Q?Johannes_Schl=FCter?= Cc: Etienne Kneuss , Derick Rethans , internals@lists.php.net Content-Type: multipart/alternative; boundary=20cf307f399e48b54204a627371c Subject: Re: [PHP-DEV] Negative string offsets From: robert@xarg.org (Robert Eisele) --20cf307f399e48b54204a627371c Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 2011/6/20 Johannes 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 al= so > 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) > Yes, sure. But if this feature is documented well, I can't see any problems with this, especially if the trend goes towards a more typed language where the user knows about the used data-type. > 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. > I know about the equality of the two bracket forms. But I read somewhere that the trend goes towards [] - and maybe it was something from you. > > johannes > > > 2011/6/20 Johannes Schl=FCter > > > > > 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 smart= er > 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 =3D array(-1 =3D> "foo", 2 =3D> "bar"); $a[-1] should reall= y 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 > > > > > > > > > > > > --20cf307f399e48b54204a627371c--