Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62617 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90257 invoked from network); 1 Sep 2012 04:00:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Sep 2012 04:00:25 -0000 Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.42 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.160.42 mail-pb0-f42.google.com Received: from [209.85.160.42] ([209.85.160.42:35271] helo=mail-pb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 04/E0-12451-05881405 for ; Sat, 01 Sep 2012 00:00:23 -0400 Received: by pbbrp8 with SMTP id rp8so5646867pbb.29 for ; Fri, 31 Aug 2012 21:00:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=references:in-reply-to:mime-version:content-transfer-encoding :content-type:message-id:cc:x-mailer:from:subject:date:to; bh=Wfkb6cUXEOzCV9NnQkIj7Ig7pTJPEQRgnWbKYMywmxY=; b=DektNyPaEC268TH++MUI+7ufyJ5xjhopp6XnzKPaEa7iwj1hwfFPkeQEzUxWZT06Vw NE2jGv82bqzYUUJCqI1gb7GTiQaHGMlZSbao07hfZWxONbX7JfURduNAAR+xi+xN2TRO TV9jrynPXe5wz9SCGzRiOlVVWrehrMH5kB9XYEtR/JuIKwkB8G2FKZp/1Kqasnn3xgoL li1gMqWtH6GUNBJqBnqPGvRliXbevrFJmddM7txFdNHqEJgMUUICwWeu9su3m13iNLDz XccQhQeImvo90uH+D3bH1P7yomBQK9AyJ5VZwEdy4MzPvgDRiS9GQH/waaEIf3m80gS8 8wYw== Received: by 10.68.213.138 with SMTP id ns10mr21292356pbc.157.1346472001263; Fri, 31 Aug 2012 21:00:01 -0700 (PDT) Received: from [10.220.142.109] ([111.65.28.36]) by mx.google.com with ESMTPS id pj10sm4793785pbb.46.2012.08.31.20.59.59 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 31 Aug 2012 21:00:00 -0700 (PDT) References: In-Reply-To: Mime-Version: 1.0 (1.0) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=GB2312 Message-ID: Cc: Ferenc Kovacs , "internals@lists.php.net" X-Mailer: iPhone Mail (9B206) Date: Sat, 1 Sep 2012 11:59:53 +0800 To: Rasmus Schultz Subject: Re: [PHP-DEV] Support negative indexes for arrays and strings From: tjerk.meesters@gmail.com (Tjerk Meesters) On 1 Sep, 2012, at 1:11 AM, Rasmus Schultz wrote: > Yes, typo! sorry. >=20 > $array =3D array(1001, 1002, 1003, 1004); > $number =3D $array[-1]; // =3D> 1004 > $array[-1] =3D 1005; > $number =3D $array[-1]; // =3D> ???? >=20 > Looking at the resulting code, I would like to point out also that > it's extremely misleading... because $array[-1] references two > completely different elements depending on whether you're reading or > writing the value... unless $array[-1] =3D 1005 would actually overwrite > the last element in the array - in which case it gets even more > dangerous, as well as breaking backwards compatibility... That might actually be something I could use :) But the fun for me begins he= re: $numbers =3D array(); $numbers[-1] =3D 5; $numbers[] =3D 6; What would have happened to the keys? Normally [] is equivalent to [count($n= umbers)].=20 Perhaps this is why JS treats negative indices as properties instead :) >=20 >=20 > On Fri, Aug 31, 2012 at 9:24 AM, Ferenc Kovacs wrote: >>=20 >>=20 >> On Fri, Aug 31, 2012 at 3:14 PM, Rasmus Schultz wrot= e: >>>=20 >>> Having thought about this for a while, I think this is a bad idea - here= 's >>> why: >>>=20 >>> $array =3D array(1001, 1002, 1003, 1004); >>>=20 >>> $number =3D $array[-1]; // =3D> 1004 >>>=20 >>> $number[-1] =3D 1005; >>>=20 >>> $number =3D $array[-1]; // =3D> ???? >>>=20 >>> Obviously, the last statement must return 1005, since otherwise that >>> value would be inaccessible. >>>=20 >>=20 >> maybe you wanted to write >> $array[-1] =3D 1005; >> instead of >> $number[-1] =3D 1005; >> ? >>=20 >> otherwise I can't see the problem that you are mentioning. >> could you clarify? >>=20 >> -- >> Ferenc Kov=A8=A2cs >> @Tyr43l - http://tyrael.hu >=20 > --=20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >=20