Re: Re: power operator (again)
| From: | Rowan Collins | Date: | Fri, 20 Dec 2013 09:27:32 +0000 |
| Subject: | Re: Re: power operator (again) | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-70784@lists.php.net to get a copy of this message | ||
Kris Craig wrote (on 20/12/2013):
But now, let's look at another scenario: <?php $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 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 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]