Doc #76875 [Com]: It is not clear what 'uncomparable' means
| From: | a at b dot c dot de | Date: | Thu, 13 Sep 2018 11:26:31 +0000 |
| Subject: | Doc #76875 [Com]: It is not clear what 'uncomparable' means | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-15987@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76875&edit=1
ID: 76875
Comment by: a at b dot c dot de
Reported by: manabu dot matsui at gmail dot com
Summary: It is not clear what 'uncomparable' means
Status: Open
Type: Documentation Problem
Package: Documentation problem
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
"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].
Previous Comments:
------------------------------------------------------------------------
[2018-09-13 01:11:19] manabu dot matsui at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/language.operators.comparison
---
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.
<?php
$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)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76875&edit=1