Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62606 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18586 invoked from network); 31 Aug 2012 13:14:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Aug 2012 13:14:15 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.212.42 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.212.42 mail-vb0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:48181] helo=mail-vb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D4/A1-09246-5A8B0405 for ; Fri, 31 Aug 2012 09:14:15 -0400 Received: by vbbfs19 with SMTP id fs19so3345741vbb.29 for ; Fri, 31 Aug 2012 06:14:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type :x-gm-message-state; bh=+P7yw0D9XCFHDze+VTHk4v/BzH3ZOoPWdUsYBAtvmY8=; b=Kuc3ILLxfKht9j1dJD3vPhUc8y98NxPZXxd+88j+JSopMwY+FFZy0qpw3CSrGBSIXJ v7zoHblnZnOiIYeiUnfLQMRVdxPM37eVLy8O60ndt9B9mbv3PxRZBCdnOWB2gnm1T/nC 9ZQ7HqLL2/iSv9LTnDZKQWlwiAGa6LJbhT0ofKyD6txJEqDTMKmCZiUf36GF5Ois8kzR 69UBbgpVByXI8qmOV/AYTuwJe1dxhYd6QEeN1rgB8eceGBa3NlDuvYXfDRpBnpJb5WgH 1U1Ybe7JWgSbXZIXa3e9KBMwc3rQ69NXu4yVp0BIDk9sKOe9zb70dQt8fA9LKDzZccAZ AElw== MIME-Version: 1.0 Received: by 10.58.171.130 with SMTP id au2mr5466932vec.26.1346418850574; Fri, 31 Aug 2012 06:14:10 -0700 (PDT) Received: by 10.58.91.162 with HTTP; Fri, 31 Aug 2012 06:14:10 -0700 (PDT) Date: Fri, 31 Aug 2012 09:14:10 -0400 Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 X-Gm-Message-State: ALoCoQnqAKKY0DM7W/vPtZ7SnhDIv2sDolUFFPRBvmnAqqlOKWi8mccMCHpDbc1P6hHU/muUw4mK Subject: Re: [PHP-DEV] Support negative indexes for arrays and strings From: rasmus@mindplay.dk (Rasmus Schultz) Having thought about this for a while, I think this is a bad idea - here's why: $array = array(1001, 1002, 1003, 1004); $number = $array[-1]; // => 1004 $number[-1] = 1005; $number = $array[-1]; // => ???? Obviously, the last statement must return 1005, since otherwise that value would be inaccessible. On the other hand, to know whether you have to know whether your array is currently a hash or not - since array index now works completely differently depending on whether your array is currently a hash or an array. This is not something you can currently even test for - and not something you should really need to know or care about in the first place. Having to know this information in certain cases would defeat the purpose of having a single collection-type in the first place: it really *should* work the same, all the time. Just my $0.02... -- From: Marc Easen To: "internals@lists.php.net" , Lars Strojny Cc: Date: Sun, 17 Jun 2012 20:53:38 +0100 Subject: Re: [PHP-DEV] Support negative indexes for arrays and strings Hi Lars, I don't think there needs to be a new operator, as it is possible to achieve this behaviour without adding a new language construct. The odd thing with PHP as I'm sure you are aware of is that arrays can be either a lists or a dictionary. This is where this becomes quite difficult to implement: Numerical keyed array: $a = array('foo', 'bar', 'baz'); $a[0] === 'foo' I would expect: $a[-1] === 'baz'; An string keyed array: $b = array('foo' => 1, 'bar' => 2, 'baz' => 3); $b[0] === 1; 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. 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. 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'. Thanks, Marc