Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91202 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 68613 invoked from network); 11 Feb 2016 12:48:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Feb 2016 12:48:08 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.49 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.49 mail-wm0-f49.google.com Received: from [74.125.82.49] ([74.125.82.49:38299] helo=mail-wm0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3E/49-25203-5038CB65 for ; Thu, 11 Feb 2016 07:48:07 -0500 Received: by mail-wm0-f49.google.com with SMTP id p63so66851604wmp.1 for ; Thu, 11 Feb 2016 04:48:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=DLAk03YliMyTfniE75nS+9wFvJzcd7tbLkuAUNtpbRU=; b=Xv2p2yTMo9/85Xr+y/13EDqqRuR9A5kR6E+4m4haB7pbM9Yh2IfUjS0HHo0P0aD2Ov egZWGPzu5YBCTUZ4+O24nBue95ooAYUsE7mZxAFPVbmFaZvD3BXU2mpMOXoLSbytvjE4 nFWcAm68YTBzonR9jLzom/p1pAE80pY6zfB6guCHeI+Zci9TNLGolmN7p/LdfJgNeIEJ vQ/3HwNbUzWB5K75DjgUREfsrktZYLvAG5WSBuP5zc5+sW+Xmqs7E5wOsYGCT7uMaxZi amOG5jszy7pXHusIava/qUIRxK7T3vgdqw6GgjdD1T2MdusllJq51wcf8fGa4sip2fPJ Xl5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-type :content-transfer-encoding; bh=DLAk03YliMyTfniE75nS+9wFvJzcd7tbLkuAUNtpbRU=; b=ERmvWP8jqUYJIA6ze9f/rSp/qT0XHX/COvQeY/AxuJzc0SHMrolZlVmx0dQlklb5XF qIkadnkQMFa9O3uGKUdG5VXrTFtgOVH2bb7W98hKbz8iz4MmwS31ifHoF35iuRVKibzB legFNNcN1WPnxg2SCmijNQier2u/V4gqhXcfkbkP5JNITtyZFvCJGeJWoyLBC7C16PIP P03Ksdf0LURP4oMBG1BJvhS9xgCWCP9Dpj+lf5tBy4srxzV72+fr2ZqsTmwbbzMEpo7S htZzg8d129ixiC0U0gQPy5BlhHwfVxk2TvPCEqbsSPouDS4M1KRf4nhQTPx9GBfLp2ON iN3g== X-Gm-Message-State: AG10YORkb8Ja7kGqKiSoPFOBOo2yieWnPCS80Ya5/Ks4Z+8aJocR8eZbztEYqlwKHZQBxA== X-Received: by 10.194.157.3 with SMTP id wi3mr45677890wjb.30.1455194882733; Thu, 11 Feb 2016 04:48:02 -0800 (PST) Received: from [192.168.0.152] ([93.188.182.58]) by smtp.googlemail.com with ESMTPSA id w17sm7895223wmw.5.2016.02.11.04.48.01 for (version=TLSv1/SSLv3 cipher=OTHER); Thu, 11 Feb 2016 04:48:01 -0800 (PST) To: internals@lists.php.net References: <56A3A01F.1020500@php.net> <56BB4A5F.3060906@php.net> <56BC29C8.9070308@gmail.com> <56BC3372.1010308@gmail.com> <56BC7BB6.6070705@gmx.de> Message-ID: <56BC829C.1040608@gmail.com> Date: Thu, 11 Feb 2016 12:46:20 +0000 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: 7bit Subject: Re: [PHP-DEV] [RFC] Generalize support of negative string offsets From: rowan.collins@gmail.com (Rowan Collins) Christoph Becker wrote on 11/02/2016 12:16: > 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). Indeed, this is a big problem with making the string offset functionality richer in general, because PHP has no "char" type, only a single-character string. This leads to some odd things: // string[0] returns a one-char string, which has an element [0], so you can keep adding [0] for as long as you like: $foo = 'abc'; echo $foo[0][0][0][0][0]; // a // assignment to an offset only overwrites one character, but the source can be a string of any length: $foo = 'abc'; $foo[0] = 'zzz'; echo $foo; // zbc String offsets simply can't behave like array offsets within PHP's current type system, which is why I favour dedicating {} syntax to them, and making it work *usefully*, rather than trying to make it look like arrays. Then, it would be less surprising for $string{-1} to behave differently from $array[-1], and that $string{} is a syntax error. Regards, -- Rowan Collins [IMSoP]