Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92099 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52579 invoked from network); 5 Apr 2016 12:08:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Apr 2016 12:08:44 -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.44 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.44 mail-wm0-f44.google.com Received: from [74.125.82.44] ([74.125.82.44:35822] helo=mail-wm0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D9/A4-27948-CCAA3075 for ; Tue, 05 Apr 2016 08:08:44 -0400 Received: by mail-wm0-f44.google.com with SMTP id 191so22245392wmq.0 for ; Tue, 05 Apr 2016 05:08:43 -0700 (PDT) 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-transfer-encoding; bh=+CdjT1DZrrmqdkS5/9F3qO4J616F6zF4LrZS/LvFVXg=; b=nRyoQFgoX4fEtdZhLB1sCa2yi2mBqPVh74zK5u/zmAVcg7smpYSYQbUaNqkzHLprjf qXy5BbiJR4Xj8RP0/QXZhRf2QCJFVHEVVD1eA8bwM3ztCOhJ4GhkRpgZVAfdeiQlAEe4 UMKH+zmbYACb1DeMUB2gfiQRasVDH/YersRenkBBZNgFpGLMttv4lSJj1oXyuIR10JKS GZpSGs8Fpo+Hcvxh3MUks2J0NOQWm27LVDCg4czlx3yHwQbtEUPCGB2nozWDMwTYWU7y 8DmjvcsF9OZWO1WF8iSoJ2/hF7NzgCtcBLmWreQZHZZcNed7MnPnktfS1ke0qPUfuzn9 jaog== 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-transfer-encoding; bh=+CdjT1DZrrmqdkS5/9F3qO4J616F6zF4LrZS/LvFVXg=; b=apGnWVYHSjtzm+oUtkaUXWAS+fcRJUjL/ytTZrvZ4EDxdZEzld7lRHHQDWu1tGfO7N vuVr5NBmXMXMiR1cjPLQCaPL7L8+x3KpkfnoD1CMF9/xPATRkya4a7yU3C1+Hpvm4+00 LDcBKDPRe92NB2dFMQQl9WzQQd2cd5kAjM5kvCvcW7UTMhQhSIsIarMnOmMqrusheBsK kXWOp61ah0QUZczm4cmnqbFLEkchxcuYKVhO4sRbOCztJhPFofYraUixQJN1LoYmglwT 22oDJN45WzH8dcuyQbjEyx4O4yUCUPv1D368dIm44WaBkKVjvyQcT7ojjayEUlwtLSKM vdxQ== X-Gm-Message-State: AD7BkJLLmnDv+uZR48eMkJ3vE2u1GmdIIb1DmaF6qqiomf0tk3cPw1FkQLXJqxyooAOh4g== X-Received: by 10.28.211.1 with SMTP id k1mr18230265wmg.93.1459858121093; Tue, 05 Apr 2016 05:08:41 -0700 (PDT) Received: from [192.168.0.86] ([93.188.182.58]) by smtp.googlemail.com with ESMTPSA id ux5sm34342703wjc.17.2016.04.05.05.08.40 for (version=TLSv1/SSLv3 cipher=OTHER); Tue, 05 Apr 2016 05:08:40 -0700 (PDT) To: internals@lists.php.net References: Message-ID: <5703AA3B.4010000@gmail.com> Date: Tue, 5 Apr 2016 13:06:19 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Copy On Write and Assign By Reference perform different on PHP5 and PHP7 From: rowan.collins@gmail.com (Rowan Collins) Sara Golemon wrote on 01/04/2016 02:52: > On Thu, Mar 31, 2016 at 9:47 AM, Huqiu Liao wrote: >> I have a question about Assign By Reference and I posted on StackOverflow, >> I'd like to know the reason behind it, and I did not get any this kind of >> answer, can anyone give me some clues. >> > Are you asking out of curiosity? Or because you think a new bug has > been introduced in PHP7? > > If the latter, I'd respond by pointing out that the behavior of using > multiple operations with side-effects (like pre/post inc/dec) is > defined as undefined. That is, while the PHP reference implementation > may give you a particular result, you should not rely on that result. > I just dug into the spec out of curiosity, and I have a nit-pick: there is relevant language under "Section 10: Expressions" [1]: > Unless stated explicitly in this specification, the order in which the operands in an expression are evaluated relative to each other is unspecified. [...] (For example,[...] in the full expression $j = $i + $i++, whether the value of $i is the old or new $i, is unspecified.) But arguably this doesn't go far enough to justify the PHP 5 engine's behaviour in this case, because it only mentions the *order* of evaluation being unspecified, not the actual semantics. The definition of the pre-increment operator [2] states: > The result is the value of the operand after it has been incremented. That is, the operator does not return the operand itself, but its value at a particular time. However, there is no order of execution which allows the value of the variable to be 4 on both sides of the addition; to get this requires the actual behaviour of the ++ operator to be re-defined as "return a reference to the incremented operand". (You could make an argument for the two increments happening "simultaneously" and giving a result of 6, but to get 8, they have to both happen simultaneously *and* see each other's results.) I'm not seriously suggesting that the PHP 5 behaviour is problematic, but unless there are additional caveats somewhere else, it does seem to violate the letter of the current spec. [1] https://github.com/php/php-langspec/blob/master/spec/10-expressions.md [2] https://github.com/php/php-langspec/blob/master/spec/10-expressions.md#prefix-increment-and-decrement-operators Regards, -- Rowan Collins [IMSoP]