Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91047 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64478 invoked from network); 1 Feb 2016 17:21:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Feb 2016 17:21:50 -0000 Authentication-Results: pb1.pair.com header.from=francois@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=francois@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 212.27.42.2 as permitted sender) X-PHP-List-Original-Sender: francois@php.net X-Host-Fingerprint: 212.27.42.2 smtp2-g21.free.fr Received: from [212.27.42.2] ([212.27.42.2:63761] helo=smtp2-g21.free.fr) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D7/D8-07168-C249FA65 for ; Mon, 01 Feb 2016 12:21:49 -0500 Received: from [127.0.0.1] (unknown [82.240.16.115]) (Authenticated sender: flaupretre@free.fr) by smtp2-g21.free.fr (Postfix) with ESMTPSA id 92C624B003F; Mon, 1 Feb 2016 18:19:32 +0100 (CET) To: Stanislav Malyshev , Nikita Popov References: <56A3A01F.1020500@php.net> <56AE8735.4070901@gmail.com> Cc: Internals Message-ID: <56AF9426.5070107@php.net> Date: Mon, 1 Feb 2016 18:21:42 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <56AE8735.4070901@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Antivirus: avast! (VPS 160201-0, 01/02/2016), Outbound message X-Antivirus-Status: Clean Subject: Re: [PHP-DEV] [RFC] Generalize support of negative string offsets From: francois@php.net (=?UTF-8?Q?Fran=c3=a7ois_Laupretre?=) Le 31/01/2016 23:14, Stanislav Malyshev a écrit : > Hi! > >> The only concern I have is that support of negative indexing will break >> symmetry with (proper) arrays, where we cannot support negative indexing. > > I think that was the main source of objections to this proposal in the > past. However, as one might say, string offsets are already not > symmetrical to array offsets - e.g. you can do $array["foo"] but not > $string["foo"]. > >> However this is unlikely to be a significant issue. (I do however play with >> the thought of reutilizing the obsolete {} indexing syntax to act as offset >> indexing instead.) > > I think it may be a good idea to start recommending using {} for string > offsets and [] for arrays. While both syntaxes may work for strings, the > intent (and expected handling of negatives, in this case) is much > clearer when different syntax is used. > Yes, authorizing array-related '[]' syntax on strings may look fine at first sight, but it only brings some unwanted ambiguity for no real benefit. And ambiguity increases with the support of negative string offsets. So, I just added a chapter to the RFC, saying that documentation would be modified to recommend using the '{}' syntax for string offsets. Regards François