Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70811 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81397 invoked from network); 21 Dec 2013 11:59:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Dec 2013 11:59:58 -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.174 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.174 mail-we0-f174.google.com Received: from [74.125.82.174] ([74.125.82.174:54350] helo=mail-we0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 72/54-50487-CB285B25 for ; Sat, 21 Dec 2013 06:59:57 -0500 Received: by mail-we0-f174.google.com with SMTP id q58so3505877wes.33 for ; Sat, 21 Dec 2013 03:59:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=4OfWNc8sBXZz5pNrbvesMF7lwW3s2Mn+kcN2GYxrZk0=; b=XGKbFqXKTMHVMZnM8cYT9S2DvCL9IlefOFck0XI+mdvtC2ewPdMd4+PdGnTAWa3tP1 dmElPoMxs9+5jiXUMCwakW1sEzV3kruHeXZDFZpm1kmrMBQrBGvIS/AdbEav38EM4jJy CIV3VQQIxGEsadd7pzCIQEtgA7MZfIKLl7JNdqYSmzfJClSKH98uD5bKPYcfV1+Ufup1 nDLKlIRSYaUjw+8Z548mt0hfIj+lUdw9BHj6pru+hJT+T466GzO3UDNolYT+H3PpTKRs ypvR1vGWPY7TyIDqlp5o/IVU/DO9Bb/IqiENXmoSLYiB2W1uXos6TQqgiVOcnZdVgild 0pNg== X-Received: by 10.180.106.229 with SMTP id gx5mr11281905wib.55.1387627193701; Sat, 21 Dec 2013 03:59:53 -0800 (PST) Received: from [192.168.0.2] (cpc19-brig17-2-0-cust25.3-3.cable.virginm.net. [81.101.201.26]) by mx.google.com with ESMTPSA id wy5sm4724368wjc.8.2013.12.21.03.59.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 21 Dec 2013 03:59:52 -0800 (PST) Message-ID: <52B582A4.1020504@gmail.com> Date: Sat, 21 Dec 2013 11:59:32 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: internals@lists.php.net References: <52B40D84.7000209@gmail.com> <001e01cefe37$7718bf50$654a3df0$@tutteli.ch> In-Reply-To: <001e01cefe37$7718bf50$654a3df0$@tutteli.ch> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: power operator (again) From: rowan.collins@gmail.com (Rowan Collins) On 21/12/2013 10:29, Robert Stoll wrote: > echo ( -3 * 2); // -6 > $x = -3; > echo $x * 2; // -6 -> does not behave like (-3) * 2 This is an extremely poor choice of example: (-3) * 2 and -(3*2) both evaluate to -6 anyway, since unary minus is effectively multiplication by -1, and therefore commutative with multiplication. However, the last line *does* behave like "(-3) * 2", because left operand of the * has already been calculated and stored in $x; it could have been calculated using "$x = 10 - 13", in which case you could see it as equivalent to "(10 - 13) * 2" - the brackets basically meaning "calculate this bit first before you even look at the rest of the expression". > Nope, that's not true. 1+2 is just already evaluated and the result was stored in $x rather than the expression. That is exactly what I was trying to say: the expression $x * 3 does not need any rules of operator precedence, because it has only one operator (unless you count the $ sigil as an operator); if $x was previously assigned based on some other expression, the details of that expression are entirely irrelevant, only their answer matters. The point being that all this discussion of precedence only applies if the unary minus operator appears *in the same expression* as the power operator. But it's very unlikely that anyone would write "$sq = -3 ** 2" rather than just "$sq = 9"; more likely, they will write "$sq = $calculated_value ** 2", which has no ambiguity, and will work as expected for any value of "$calculated_value". Regards, -- Rowan Collins [IMSoP]