Doc #71902 [Opn]: Invalid precedence order of => (T_DOUBLE_ARROW) operator

From: Date: Thu, 31 Mar 2016 15:59:20 +0000
Subject: Doc #71902 [Opn]: Invalid precedence order of => (T_DOUBLE_ARROW) operator
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-13369@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71902&edit=1 ID: 71902 Updated by: cmb@php.net Reported by: vnd at vndh dot net Summary: Invalid precedence order of => (T_DOUBLE_ARROW) operator Status: Open Type: Documentation Problem Package: Scripting Engine problem Operating System: N/A PHP Version: 5.6.19 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: > I'd remove that whole paragraph. ACK. For the record: that paragraph had been added to fix bug #51454, and the "wrong precedence" had already pointed out back then, obviously going unnoticed. > => is weird because it's not really an operator like everything else. ACK. Listing the comma as operator seems even worse, though (bug #66772). Previous Comments: ------------------------------------------------------------------------ [2016-03-26 05:33:08] requinix@php.net (Modifying the summary to include searchable terms.) => is weird because it's not really an operator like everything else. It's a token used in other expressions and constructs, like arrays or foreach. I don't think it makes sense to include it in the operator precedence table at all. Then there's > For arrays, assigning a value to a named key is performed using the "=>" > operator. The precedence of this operator is the same as other assignment > operators. In the context of "assignment operators", it suggests to me that one is supposed to write code like $array = array(); $array["foo"] => "bar"; which is, of course, wrong. I'd remove that whole paragraph. ------------------------------------------------------------------------ [2016-03-25 19:50:47] vnd at vndh dot net Description: ------------ The array's value to key assignment operator "=>" priority is less than the priority of operators "and", "xor" and "or". It can be verified by the code attached to this issue. I also assume that this is documentation problem as the priority of logical operators seems valid in the mentioned context. I've found two pages where the documentation is wrong: 1) http://php.net/manual/en/language.operators.assignment.php states that: "The precedence of this operator is the same as other assignment operators". 2) http://php.net/manual/en/language.operators.precedence.php shows that "=>" operator has the same priority as other assignment operators. Test script: --------------- // below expression should not evaluate nor be lexically valid when "=>" has the priority over "and", "xor" or "or" var_dump(array("a" => true and false xor false or false)); ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71902&edit=1

« previous php.doc.bugs (#13369) next »