php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #71902 Invalid precedence order of => (T_DOUBLE_ARROW) operator
Submitted: 2016-03-25 19:50 UTC Modified: 2016-03-31 16:07 UTC
From: vnd at vndh dot net Assigned: cmb (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.6.19 OS: N/A
Private report: No CVE-ID: None
 [2016-03-25 19:50 UTC] 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));


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-26 05:33 UTC] requinix@php.net
-Summary: Invalid order of operators +Summary: Invalid precedence order of => (T_DOUBLE_ARROW) operator -Package: Documentation problem +Package: Scripting Engine problem
 [2016-03-26 05:33 UTC] 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-31 15:59 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2016-03-31 15:59 UTC] cmb@php.net
> 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).
 [2016-03-31 16:06 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=338859
Log: fixed #71902 (Invalid precedence order of => (T_DOUBLE_ARROW) operator)

Actually, T_DOUBLE_ARROW isn't an operator.
 [2016-03-31 16:07 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 [2016-03-31 16:07 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2020-02-07 06:07 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=acc7076441ef06d9b7739fb22b5b0159fa35f9d8
Log: fixed #71902 (Invalid precedence order of => (T_DOUBLE_ARROW) operator)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 07 14:01:32 2024 UTC