php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #70850 error in summary of array comparison
Submitted: 2015-11-03 21:53 UTC Modified: 2017-01-28 13:53 UTC
From: JQKP at example dot com Assigned:
Status: Verified Package: Arrays related
PHP Version: 5.6.15 OS: MS Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: JQKP at example dot com
New email:
PHP Version: OS:

 

 [2015-11-03 21:53 UTC] JQKP at example dot com
Description:
------------
---
From manual page: http://www.php.net/language.operators.comparison
---

> Array with fewer members is smaller, if
> key from operand 1 is not found in operand
> 2 then arrays are uncomparable, otherwise
> - compare value by value

This is not true. See my test script below.

(However, the "Example #2 Transcription of standard array comparison" on the manual page does seem to be true.)

Test script:
---------------
C:\Users\Michael>php
<?php
$a=[1=>1,2=>3];
$b=[1=>2,6=>7];
print $a<$b;
# This prints 1 because it compares the first keys.
# However, according to the manual, as quoted above,
# it should print '' because "key from operand 1
# [namely 2] is not found in operand 2".


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-11-03 22:57 UTC] requinix@php.net
It's not so much wrong as it is unclear how the comparison works. It doesn't check all the keys in operand 1 against those in operand 2 and *then* do the value comparison. Rather, as it loops through operand 1 it first checks that operand 2 has the key before trying to compare their two values.

https://3v4l.org/1QXcc
 [2017-01-28 13:53 UTC] cmb@php.net
-Status: Open +Status: Verified -Package: Documentation problem +Package: Arrays related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC