Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68254 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 34577 invoked from network); 20 Jul 2013 05:27:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jul 2013 05:27:18 -0000 Authentication-Results: pb1.pair.com smtp.mail=leight@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=leight@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.176 as permitted sender) X-PHP-List-Original-Sender: leight@gmail.com X-Host-Fingerprint: 209.85.220.176 mail-vc0-f176.google.com Received: from [209.85.220.176] ([209.85.220.176:45617] helo=mail-vc0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 93/6E-13120-5BF1AE15 for ; Sat, 20 Jul 2013 01:27:17 -0400 Received: by mail-vc0-f176.google.com with SMTP id ha12so3629720vcb.7 for ; Fri, 19 Jul 2013 22:27:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=A9URMsTMhiScKk4jj6zH6elMJ6HcD+60r8hd4bcA2wo=; b=LCxTEEGEOp7wrbeGfO2/RhckAlYkeyDyCLNl74M7m42VbuB+dvVxvndHlHr2AMLLSf s4e9+3+PLVU1F8pfH+HvxZ+DU6X1mAMZADQgzr5IHDdW6ZOGWTcHJfUKoA3+mZ6CRTHo 0eJVOmlGsrsHtwpKIz+A59adqda12W6blpQoW1J4Fy3if6FAfoyLVoBGQqqSft57X/pE P3qEADfAThp9smB4WEzX/uEcCC/7WrIujEVYqyX49iUxL1K4BQDkuVV21LEzReUse526 RRqG16i2Oz2C2XX4z9/7EZCpZ84ENBUtKKN1tshN+85Iu6Amig0wVYZn7BLoEtE1xKeN tt2g== MIME-Version: 1.0 X-Received: by 10.58.31.106 with SMTP id z10mr6851153veh.61.1374298034647; Fri, 19 Jul 2013 22:27:14 -0700 (PDT) Received: by 10.52.90.144 with HTTP; Fri, 19 Jul 2013 22:27:14 -0700 (PDT) In-Reply-To: References: Date: Sat, 20 Jul 2013 06:27:14 +0100 Message-ID: Cc: PHP internals Content-Type: multipart/alternative; boundary=089e013a2a622bb78b04e1eab2ea Subject: Re: [PHP-DEV] Operator precedence is undefined? From: leight@gmail.com (Leigh) --089e013a2a622bb78b04e1eab2ea Content-Type: text/plain; charset=ISO-8859-1 I'm disappointed $a+++++$a doesn't work as expected :( On 20 July 2013 06:08, Sherif Ramadan wrote: > Sara, > > On Sat, Jul 20, 2013 at 12:44 AM, Sara Golemon wrote: > > > What's undefined isn't the relationship between preinc/postinc and add. > > What's undefined is the use of multiple preinc/postinc operators within > a > > single expression > > > > I'm sorry but I can not find any evidence of how that is undefined. The > operators are right-associative, with a defined level or precedence. Their > operands are well defined and their return value in the expression is > determined by the compiler, not the parser. In this sense the compiler > always executes those opcodes first and returns a temporary variable. > > > > (preincrements in particular). Our parser grammer, as it currently > > stands, does have a predictable order, but that is a side-effect of > > implementation. The language's definition of order of resolution of > > multiple preinc/postinc elements within a single ticked statement is that > > they are undefined. And *that* is what made your *particular* change to > > the documentation incorrect. > > > > The parser grammar in general is pretty muddled, I will agree with that. > However, the precedence order here is well defined within the expression. I > can not see any condition under which the compiler will introduce > unpredictable order of these opcodes or their results. > > > > > > If you'd like to define behavior for: echo ++$a + 1; then that's a > > different matter. Defining the behavior of ++$a + $a++, however is > > inviting misunderstanding*. > > > > What was inappropriate, was asking for comment, receiving comment which > > cited an issue, then committing without discussing that issue first. > > > > -Sara > > > > * Even if, technically, either order of evaluation will result in the > same > > answer for this contrived expression. ++$a * $a++ is a more obviously > > ambiguous answer for a language which explicitly does not define an order > > of resolution. > > > > By that logic we should indicate that -$a * $a is also undefined behavior? > I know the parser grammar is not well-defined and I'm taking this fact into > consideration, but here we are talking about operators which will compile > down into very much well-defined opcodes and have a predictable order of > resolution. It's quite possible that someone could introduce a change later > on that will cause a different result, but the likelihood of that becoming > a reality is slim-to-none. > > I'm not a fan of getting into cat and mouse games over these types of > discussions, however. I posed my opinion on this matter and I refuse to > overwrite someone's commit because I feel my opinion is the only one that > counts. I am certainly not above being wrong. I just want to be sensible. > > > > > > > > On Fri, Jul 19, 2013 at 9:28 PM, Yasuo Ohgaki > wrote: > > > >> Hi Sara, > >> > >> 2013/7/20 Sara Golemon > >> > >>> On Fri, Jul 19, 2013 at 7:16 PM, Yasuo Ohgaki >wrote: > >>> > >>>> > >>>> > >>>> If there aren't comments, I'll rewrite the example. > >>>> > >>>> > >>>> There were comments. I explicitly told you that that the behavior is > >>> defined as undefined. You CHOSE to ignore that comment. You CHOSE to > >>> break the documentation. > >>> > >> > >> If there is defined precedence, arithmetic operation should follow it. > >> If there is exception, it should be documented. > >> > >> I don't understand why/how the arithmetic operation can be > >> ambiguous with defined precedence. (++ and -- are higher than +) > >> > >> $a = 1; > >> echo ++$a + $a++; > >> > >> should always print 4 with current PHP precedence definition. > >> If it does not, it's a bug in language. > >> > >> // mixing ++ and + produces undefined behavior > >> $a = 1; > >> echo ++$a + $a++; // may print 4 or 5 > >> > >> I don't see any reason it became undefined. > >> If this kind of simple precedence is broken, how programmers write > >> code and/or trust the language? > >> > >> http://3v4l.org/mR4da/vld#tabs > >> > >> This site seems support PHP 4.3.0 to PHP 5.5.0 and opcode looks > >> fine. Am I missing something? > >> > >> If you would like to suggest use of (), it should be done differently. > >> IMHO. > >> The comment only ruins PHP's reputation as language. > >> > >> Regards, > >> > >> -- > >> Yasuo Ohgaki > >> yohgaki@ohgaki.net > >> > > > > > --089e013a2a622bb78b04e1eab2ea--