Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85329 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22234 invoked from network); 20 Mar 2015 20:52:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Mar 2015 20:52:13 -0000 Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.53 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.220.53 mail-pa0-f53.google.com Received: from [209.85.220.53] ([209.85.220.53:34650] helo=mail-pa0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5B/B9-64120-D788C055 for ; Fri, 20 Mar 2015 15:52:13 -0500 Received: by pacwe9 with SMTP id we9so119730590pac.1 for ; Fri, 20 Mar 2015 13:52:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=uXZ3wbIJjPs+WQAeX3fB1CaJ0WS1gNxeIwLML8rCyLU=; b=pk0O/3at+C4OLZHPR2baYvMD5m0pvVtDl6jk9uvW6ZdQ92cnoyZgTP0uzDe26eNwlB OzCEhc13THhKbH5zXrpz+8JsZgZq00wRzTQDXR+0Gpmq9mK55evH0UwDUC5jADWKLso9 +9Wlu7eJmWMwT3k6ChAGwPndkUXzWiH07DdMNnqJ8mDvcskERdKR/RyhWjPOpXLpCy5Z sZViDxBKfJ469iNcGPUcWbaSGrt05RpKKpwvpHm0+DqL1Z3CqP0pCGwo7kxrpyGQBLVv 1uT+3FUFp/hjE4qvTttfRL8w6jaML6daGKa5HG/URtPCrJhqwZ6WBfPcwunBwMbZVneI FWnQ== X-Received: by 10.66.241.36 with SMTP id wf4mr135263539pac.8.1426884730659; Fri, 20 Mar 2015 13:52:10 -0700 (PDT) Received: from Stas-Air.local (108-66-6-48.lightspeed.sntcca.sbcglobal.net. [108.66.6.48]) by mx.google.com with ESMTPSA id bz3sm9647798pab.2.2015.03.20.13.52.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Mar 2015 13:52:10 -0700 (PDT) Message-ID: <550C8879.70002@gmail.com> Date: Fri, 20 Mar 2015 13:52:09 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: internals@lists.php.net References: <550B5A81.1090706@gmail.com> In-Reply-To: <550B5A81.1090706@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] RFC - Array slice syntactic sugar From: smalyshev@gmail.com (Stanislav Malyshev) Hi! >> My proposal is something similar to Pythons slice, in PHP this would look >> like: >> >> $slided = $array[1:4] >> >> This will get the elements in positions 1,2,3,4. (1 through 4 inclusive), >> ignoring the actual key of the array. The result for an array will be an >> array with the keys preserved, in the same order. I'm not sure how such operation would be useful, and it definitely would not be intuitive, as $array[0] and $array[0:1] (assuming non-inclusive semantic, or [0:0] with inclusive semantics) would return completely different things. That would happen even if the array has only numeric keys! This is the main problem with this syntax - unlike most languages where it is used, PHP arrays are not vectors, they are ordered hashmaps. Sometimes this is very convenient, sometimes - like for this syntax - it is not. I think this is the major reason why such proposals failed in the past. -- Stas Malyshev smalyshev@gmail.com