|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #76875 It is not clear what 'uncomparable' means
Submitted: 2018-09-13 01:11 UTC Modified: -
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: manabu dot matsui at gmail dot com Assigned:
Status: Open Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
27 - 18 = ?
Subscribe to this entry?

 [2018-09-13 01:11 UTC] manabu dot matsui at gmail dot com
From manual page:

In table 'Comparison with Various Types', it is said that 'if key from operand 1 is not found in operand 2 then arrays are uncomparable', and according to Example 2, the standard_array_compare function returns null in that case.

When I actually tried it, each operator returned the following value.

$x = ['a' => 1];
$y = ['b' => 2];

var_dump($x < $y);   # false
var_dump($x <= $y);  # false
var_dump($x > $y);   # false
var_dump($x >= $y);  # false
var_dump($x <=> $y); # 1

I can not explain this result from the manual description. I think it would be better to explain more clearly.

What is the meaning of 'uncomparable'? For example, the following can be considered

* If $x and $y are uncomparable, $x < $y, $x <= $y, $x > $y, $x >=$y are all false, and $x <=> $y is 1.

* It returns some kind of value, but it is indeterminate what the value is. (The above example happened to be so, in different situations it could be different results)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-09-13 11:26 UTC] a at b dot c dot de
"Uncomparable" means "cannot be compared". That means there is no well-ordering on arbitrary arrays that allows such comparisons to be made in any sensible fashion (how do _you_ think $x and $y should be ordered?).

['a' => 1] < ['b' => 2], for one, evaluates to FALSE because ['a' => 1] is not less than ['b' => 2]. (The operator is defined as returning TRUE if its left argument is less than its right. This is not the case here.)

In the same way, ['a' => 1] > ['b' => 2] is FALSE because ['a' => 1] is not greater than ['b' => 2] and ['a' => 1] == ['b' => 2] is FALSE because ['a' => 1] is not equal to ['b' => 2].
 [2018-09-14 00:34 UTC] manabu dot matsui at gmail dot com
I can see that there are uncomparable arrays. However, it is a problem that what kind of results can be expected (or should not be expected) when doing comparative operations on them is not clear.

For example, if it is guaranteed that $x <= $y and $x> = $y are false for uncomparable arrays $x, $y, then a function to determine whether two arrays can be compared is able to be written as follows:

function isComparable(array $x, array $y)
     return $x <= $y || $x >= $y;

If it is not guaranteed (eg like 'undefined behavior' in C or 'unspecified behavior' in Scheme), it must be implemented in a different way.
 [2023-04-12 08:25 UTC] viveksrivastab58 at gmail dot com
Big News Post are sharing latest news about business, law, finance, home improvement, health, auto, entertainment etc. More info to visit: (
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 17 18:01:28 2024 UTC