Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70809 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75870 invoked from network); 21 Dec 2013 10:29:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Dec 2013 10:29:09 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@tutteli.ch; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=php@tutteli.ch; sender-id=pass Received-SPF: pass (pb1.pair.com: domain tutteli.ch designates 80.74.154.78 as permitted sender) X-PHP-List-Original-Sender: php@tutteli.ch X-Host-Fingerprint: 80.74.154.78 ns73.kreativmedia.ch Linux 2.6 Received: from [80.74.154.78] ([80.74.154.78:55102] helo=hyperion.kreativmedia.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9B/83-50487-17D65B25 for ; Sat, 21 Dec 2013 05:29:08 -0500 Received: (qmail 14013 invoked from network); 21 Dec 2013 11:29:02 +0100 Received: from heim-032-99.raab-heim.uni-linz.ac.at (HELO RoLaptop) (193.171.32.99) by ns73.kreativmedia.ch with (AES128-SHA encrypted) SMTP; 21 Dec 2013 11:29:02 +0100 To: "'Rowan Collins'" , References: <52B40D84.7000209@gmail.com> In-Reply-To: <52B40D84.7000209@gmail.com> Date: Sat, 21 Dec 2013 11:29:00 +0100 Message-ID: <001e01cefe37$7718bf50$654a3df0$@tutteli.ch> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQEYxRSsLHpIZSBkl4qdY6gjRkgYMQH/Zh/3A4JGMqoCMfx1xQI1/RxHm3uVq3A= Content-Language: de-ch Subject: RE: [PHP-DEV] Re: power operator (again) From: php@tutteli.ch ("Robert Stoll") > -----Original Message----- > From: Rowan Collins [mailto:rowan.collins@gmail.com] > Sent: Friday, December 20, 2013 10:28 AM > To: internals@lists.php.net > Subject: Re: [PHP-DEV] Re: power operator (again) > > Kris Craig wrote (on 20/12/2013): > > But now, let's look at another scenario: > > > > > > > $x = -3; // Or $x = -1 * 3, if you wish. > > > > $y = $x ** 2; > > > > ?> > > > > What would be the value of $y under this RFC? > > That has nothing to do with operator associativity: $x has already been > calculated as -3, just as if it were $y = (-3) ** 2 > That's actually wrong. Consider the following code snippet: echo ( -3 * 2); // -6 $x = -3; echo $x * 2; // -6 -> does not behave like (-3) * 2 $x = "-3"; echo $x * 2; // -6 -> does not behave like (-3) * 2 But I think it would be more intuitive if it would behave as (-3) > Consider the same thing with mixed addition and multiplication: > > $y = 1 + 2 * 3; > // $y is 7, due to operator precedence > > $y = (1 + 2) * 3; > // $y is 9, due to the brackets > > $x = 1 + 2; > $y = $x * 3; > // $x is 3, so $y is 9; operator precedence is irrelevant > Nope, that's not true. 1+2 is just already evaluated and the result was stored in $x rather than the expression. > As I said before, I think people don't always think of "-3" as an > operator applied to a literal, but by the same token, they are rather > unlikely to write something like "-$x". That limits this whole debate on > associativity to those cases where somebody hard-codes a negative value > like -3, and doesn't think to add parentheses. > > Regards, > -- > Rowan Collins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php