Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105323 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 20922 invoked from network); 21 Apr 2019 22:31:31 -0000 Received: from unknown (HELO smtpproxy19.qq.com) (184.105.206.84) by pb1.pair.com with SMTP; 21 Apr 2019 22:31:31 -0000 X-QQ-mid:Yeas12t1555875082t330t29459 Received: from 14D73359B2E14ADDB4DDC3857AE32898 (me@jhdxr.com [220.255.44.152]) X-QQ-SSF:00000000000000F0F61000000000000 To: "'Nikita Popov'" Cc: "'PHP internals'" References: <003a01d4eaf0$c17d6c20$44784460$@jhdxr.com> In-Reply-To: Date: Mon, 22 Apr 2019 03:31:19 +0800 Message-ID: <000301d4f878$cbdbf160$6393d420$@jhdxr.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQIKWL9sdr8zqvFBmN46rJnDR+4gNwHUvipDpc2QWTA= Content-Language: zh-cn X-QQ-SENDSIZE: 520 Feedback-ID: Yeas:jhdxr.com:qybgforeign:qybgforeign1 X-QQ-Bgrelay: 1 Subject: RE: [PHP-DEV] [RFC] Spread Operator in Array Expression v0.2 From: me@jhdxr.com (=?utf-8?b?Q0hVIFpoYW93ZWk=?=) On Monday, April 8, 2019 9:22 PM Nikita Popov = wrote: > This looks reasonable to me. My only concern would be the = "by-reference passing" section of the RFC. The current proposal states = that [...$arr] will preserve references in $arr, which is not the = behavior I would expect. >=20 > Is this choice for parity with the unpacking functionality in calls? = In that case I think it is important to understand that for argument = unpacking the handling of references is decided by the called function, = not what is in the array. If the function accepts an argument = by-reference, then the corresponding element in the array will be turned = into a reference (regardless of whether it was one before). Conversely, = if the function accepts an argument by-value, then the element from the = array will be passed by-value (regardless of whether it was a reference = before). A similar concept doesn't really exist for unpacking in arrays. No. I understand it's decided by the definition of the function that = whether the arguments are passed by-value or by-reference, and it's not = able to be changed by the caller. So the spread operator here extracts = the array, no matter it contains referenced element or not, and the = conversion from by-ref to by-val or by-val to by-ref is done during = passing to the callee. Back to the array definition scenario, the spread = operator will also extracts the array, and it should be the array = definition to decide whether conversion is needed. Since we can define = array element by reference now, it doesn't make sense to change the way = of storing values just because it's unpacking. In other words, the = conversion of how values are stored isn't part of spread operator.