Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91203 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70635 invoked from network); 11 Feb 2016 13:05:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Feb 2016 13:05:15 -0000 Authentication-Results: pb1.pair.com smtp.mail=francois@php.net; spf=unknown; sender-id=unknown Authentication-Results: pb1.pair.com header.from=francois@php.net; 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:52120] helo=smtp2-g21.free.fr) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 68/A9-25203-9078CB65 for ; Thu, 11 Feb 2016 08:05:14 -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 23A524B016F; Thu, 11 Feb 2016 14:02:27 +0100 (CET) To: Christoph Becker , Yasuo Ohgaki , Stanislav Malyshev References: <56A3A01F.1020500@php.net> <56BB4A5F.3060906@php.net> <56BC29C8.9070308@gmail.com> <56BC3372.1010308@gmail.com> <56BC7BB6.6070705@gmx.de> Cc: Internals Message-ID: <56BC86FD.7040307@php.net> Date: Thu, 11 Feb 2016 14:05:01 +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: <56BC7BB6.6070705@gmx.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Antivirus: avast! (VPS 160211-0, 11/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 11/02/2016 13:16, Christoph Becker a écrit : > > Appending to an array always adds a single element only, consider > > $a = [1,2,3]; > $a[] = [4,5]; > > The suggested syntax for strings would concatenate an arbitrary amount > of elements (characters) to a string. IMHO, this would not be > consistent, but rather confusing. The alternative interpretation to > append the first character only, would be confusing as well (besides > there would be issues with regard to multibyte character encodings). > Not exactly, the '$str[]' syntax I suggested would have worked the same as '$str[strlen($str)]': it would have appended the first character only. Concerns about multi-bytes characters are clearly out of scope, as all string offset operations handle bytes only. Regarding consistency, I understand the arguments about the fact that string concatenation should be done using the '.' operator, but do you know that this is already supported : $str="abc"; $str[3]='def'; // $str="abcd" $str[10]='xyz'; // $str = "abc x"; So, my feeling was that, since '$str[strlen($str)]' is supported, we *already* support concatenation using string offset syntax. So, supporting '[]' and '{}' as a shortcut for '[strlen($str)]' was just a small addition for a better consistency and a more intuitive behavior. Stas and Yasuo are both right. It is not exactly related to negative string offsets but, on the other side, I probably won't bother opening an RFC for such a small change. That's why, if there had been a consensus, I would have added it to the current RFC. Regards François