Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60874 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91016 invoked from network); 17 Jun 2012 22:53:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jun 2012 22:53:04 -0000 Authentication-Results: pb1.pair.com header.from=lars@strojny.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=lars@strojny.net; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain strojny.net from 46.4.40.248 cause and error) X-PHP-List-Original-Sender: lars@strojny.net X-Host-Fingerprint: 46.4.40.248 milch.schokokeks.org Received: from [46.4.40.248] ([46.4.40.248:33284] helo=milch.schokokeks.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 13/37-49496-CCF5EDF4 for ; Sun, 17 Jun 2012 18:53:03 -0400 Received: from [192.168.178.32] (ppp-93-104-170-0.dynamic.mnet-online.de [::ffff:93.104.170.0]) (AUTH: PLAIN lars@schokokeks.org, TLS: TLSv1/SSLv3,128bits,AES128-SHA) by milch.schokokeks.org with ESMTPSA; Mon, 18 Jun 2012 00:52:57 +0200 id 000000000000001B.000000004FDE5FC9.00001759 Mime-Version: 1.0 (Apple Message framework v1278) Content-Type: multipart/signed; boundary="Apple-Mail=_574336D3-61C5-479F-B606-4BF9D3638918"; protocol="application/pgp-signature"; micalg=pgp-sha1 In-Reply-To: <4FDE35C2.9080601@easen.co.uk> Date: Mon, 18 Jun 2012 00:52:54 +0200 Cc: "internals@lists.php.net" Message-ID: <1AD1ED34-481F-4DD4-9E61-067F50136D46@strojny.net> References: <496E551C-85F0-423E-89FA-2C5245808320@easen.co.uk> <4D309A4D.9020904@sugarcrm.com> <4FCD07CA.7030605@easen.co.uk> <131ff485e2f37a4388919f1c61fd4816.squirrel@www.l-i-e.com> <4FD6436B.1080200@sugarcrm.com> <4FD65CA5.4050703@easen.co.uk> <4FDE35C2.9080601@easen.co.uk> To: Marc Easen X-Mailer: Apple Mail (2.1278) Subject: Re: [PHP-DEV] Support negative indexes for arrays and strings From: lars@strojny.net (Lars Strojny) --Apple-Mail=_574336D3-61C5-479F-B606-4BF9D3638918 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 Hi Marc, Am 17.06.2012 um 21:53 schrieb Marc Easen: [...] > Numerical keyed array: >=20 > $a =3D array('foo', 'bar', 'baz'); > $a[0] =3D=3D=3D 'foo' >=20 > I would expect: >=20 > $a[-1] =3D=3D=3D 'baz'; >=20 > An string keyed array: >=20 > $b =3D array('foo' =3D> 1, 'bar' =3D> 2, 'baz' =3D> 3); > $b[0] =3D=3D=3D 1; >=20 > Would generate an E_NOTICE: PHP Notice: Undefined offset: 0 in php = shell code on line 1. > An negative offset would also generate the same E_NOTICE. >=20 > So going back to your point, the change would only be to numeric based = arrays (list) and strings. It could be possible to string keyed arrays = to be accessed by the numeric counter parts, but I'm not familiar to = comment on if this is even possible. I see, must have overread that. This makes it slightly better but not = optimal, as too varying behavior for hashes vs. lists will be harder to = explain. We could go down that road and separate the both more and more = but given the history (and the usage patterns) of arrays in PHP I'm not = convinced this is a good idea. I would prefer something like this (and no, I don't propose using ':' as = an operator for real): $string =3D "bar"; $string:-1 // "b" $string:-2 // "r" $string:-10 // NULL $list =3D array("one", "two", "three"); $list:-1 // "three" $list:-2 // "two" $list:-10 // NULL $hash =3D array("one" =3D> 1, "two" =3D> 2, "three" =3D> 3) $hash:-1 // 3 $hash:-2 // 2 $hash:-10 // 10 As using arrays as hashes let=92s them behave in a FIFO kind of way, we = can do proper slicing. > It seems this topic has generated a lot of interest, I feel the best = way to proceed would be to write a RFC. I've never written one before so = could someone give me access to create a page on the RFC site or create = a RFC for me and give me permission to update it, my username is = 'easen'. For sure, RFC makes sense. I like the general idea, I=92m just not sure = about the syntax. cu, Lars= --Apple-Mail=_574336D3-61C5-479F-B606-4BF9D3638918 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.18 (Darwin) iQIVAwUBT95fxiQPF+sCY6wHAQL+mw/+IhQcfETx20g1jM+eiCZAPkO6tddlTmZV ZgwWwv0PUnnUUq/Q6T+WmgAFu2a6X0te4LywBQHrU2RM09TDDhqyJrGeKZHJQ6Yk 1BfS8VuwRzJhVDwxEyGKjqQkVnIXubruzCorMciejdBaEruF65fzF4WXADl+4+m6 KrVE0LwwH1B1jtHe/yDO7kDKZDrGG4M1mxfCPUEm1lnXYHhgeYrzUB3ffP5WlSF7 5K6JnYI41Q4FN2uHInkQ4hJ2q2lmi/7QuPJTbcf04ob3WgaigNb/z44uC+kMvCQf 8aBjsk9ClXjU7Oy3onLE7whg7dY7fPUUoiHRBgo9eeHEwL54bxVRoz6ea3WAjLmq c6jR95oNngDJn1X2ggbxz1JgXiFIMSYWTzdRhWcJX75MLDTJtxxFk0QOuz7U1DB1 ObmYoXb3LR+lELiXwUAI8kmc54ViIaivVtAwVj/lmCmNg9p951UXNTkxb9PAxYZZ 9ZLBxBkMevpXQIyTtUhVijxR4QU0Cnxb/2un2n3uCg8y2sSRUZV6EX4dlJplFKU8 rRyIoTGmqcJZM0C6N9QUs3R5v085eb7VW1jH47BI4HFtWUWiIRTNe1jaiCCsZOfx DKT/1nSC8C/CIMHJVSbJW3o/88oI4dVl1KwwghKwzPNvUK9yClKFpyXidTIXZViN 4eY3bLhC5rQ= =8c2D -----END PGP SIGNATURE----- --Apple-Mail=_574336D3-61C5-479F-B606-4BF9D3638918--