php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #75444 Array comparison operators unprecise
Submitted: 2017-10-26 08:12 UTC Modified: 2017-11-03 15:10 UTC
From: kvanderheijden at transip dot nl Assigned: pmmaga (profile)
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2017-10-26 08:12 UTC] kvanderheijden at transip dot nl
Description:
------------
On the PHP documentation page about array operators, the equality tests operators are misleading. See: http://us2.php.net/manual/en/language.operators.array.php

The docs say that the Identity comparison operator '===' checks the order of the elements, whereas there is no such mention on the Equality comparison operator.

This would imply that the order does not matter when comparing array's with the Equality operator. This is incorrect.




Test script:
---------------
$a = [1, 2, 3];
$b = [1, 3, 2];

echo '$a == $b: ', ($a == $b ? 'TRUE' : 'FALSE'), PHP_EOL;
echo '$a === $b: ', ($a === $b ? 'TRUE' : 'FALSE'), PHP_EOL;


Expected result:
----------------
$a == $b: TRUE
$a === $b: FALSE

Actual result:
--------------
$a == $b: FALSE
$a === $b: FALSE

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-26 08:25 UTC] pmmaga@php.net
-Status: Open +Status: Not a bug
 [2017-10-26 08:25 UTC] pmmaga@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

As the documentation states, it should only be true if both the keys and the values are the same. That is not the case in your example. The keys are not the same. Check this example: https://3v4l.org/EZv8I
 [2017-11-03 15:10 UTC] pmmaga@php.net
-Assigned To: +Assigned To: pmmaga
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Oct 30 16:01:23 2020 UTC