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

From: Date: Mon, 19 Feb 2018 12:48:41 +0000
Subject: Bug #73232 [Com]: Array ordering is inconsistant.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-214025@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
 Comment by:         spam2 at rhsoft dot net
 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:

why do you come with the same broken snippet as in https://bugs.php.net/bug.php?id=75980 on this
topic? your code is simply broken because you don't understand how weak-typing works when
return value of a boolean false is completly different meaning then int 0


Previous Comments:
------------------------------------------------------------------------
[2018-02-19 12:32:58] rolf at rolfjentsch dot de

if (isset($_SERVER['SERVER_ADDR'])) 
{
	if (strpos($_SERVER['SERVER_ADDR'],"192.168.10") >= 0)
	{
		$where="http://qnap/piwik/";
	}
	else
	{
		$where="https://www.someurl/piwik/";
	} 
} else $where="https://someurl/piwik/";

Problem arrises when >= is processed

------------------------------------------------------------------------
[2016-10-03 18:29:10] robin at patenall dot org dot uk

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.

------------------------------------------------------------------------
[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 (#214025) next »