Bug #73232 [Opn]: Array ordering is inconsistant.

From: Date: Mon, 03 Oct 2016 18:29:11 +0000
Subject: Bug #73232 [Opn]: Array ordering is inconsistant.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-204428@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73232&edit=1

 ID:                 73232
 User updated by:    robin at patenall dot org dot uk
 Reported by:        robin at patenall dot org dot uk
 Summary:            Array ordering is inconsistant.
 Status:             Open
 Type:               Bug
 Package:            Arrays related
 Operating System:   Centos
 PHP Version:        7.0.11
 Block user comment: N
 Private report:     N

 New Comment:

Based on the 'Transcription of standard array comparison' example on the php Comparison
Operators page I'd expect var_dump($b < $a) to be true and var_dump($b > $a) to be false
as $b['a'] < $a['a']. In the same way that var_dump($a < $b) should be
true and var_dump($a > $b) should be false as $a['b'] < $b['b'].

This does make array ordering comparison not commutative, but that's what the documentation
say. It also means that in no case are var_dump($a < $b) and var_dump($a > $b) both equal to
true.


Previous Comments:
------------------------------------------------------------------------
[2016-10-03 18:13:17] cmb@php.net

Well, what would you expect to be printed by

  var_dump($b < $a)

------------------------------------------------------------------------
[2016-10-03 09:54:45] robin at patenall dot org dot uk

Description:
------------
It appears that when comparing two arrays with the same keys but in different orders it is possible
for the first to be both less than and greater than the second. 

Test script:
---------------
<?php
$a = array("b" => 2, "a" => 4);
$b = array("a" => 3, "b" => 3);
/** $b = array("b" => 3, "a" => 3); This works correctly **/

if($a <  $b) echo "a is less than b\n";
if($a <= $b) echo "a is less than or equal to b\n";
if($a >  $b) echo "a is greater than b\n";
if($a >= $b) echo "a is greater than or equal to b\n";
if($a == $b) echo "a is equal to b\n";
if($a != $b) echo "a is not equal to b\n";


Expected result:
----------------
a is less than b
a is less than or equal to b
a is not equal to b


Actual result:
--------------
a is less than b
a is less than or equal to b
a is greater than b
a is greater than or equal to b
a is not equal to b


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=73232&edit=1


Thread (8 messages)

« previous php.bugs (#204428) next »