Doc #76875 [Com]: It is not clear what 'uncomparable' means

[email protected] ("viveksrivastab58 at gmail dot com") Wed, 12 Apr 2023 08:25:10 +0000
Newsgroups php.doc.bugs
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=76875&edit=1

 ID:                 76875
 Comment by:         viveksrivastab58 at gmail dot com
 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:

Big News Post are sharing latest news about business, law, finance, home improvement, health, auto, entertainment etc. More info to visit: (https://bignewspost.com)github.com


Previous Comments:
------------------------------------------------------------------------
[2018-09-14 00:34:32] 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:

<?php
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.

------------------------------------------------------------------------
[2018-09-13 11:26:31] 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-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