Doc #60688 [Opn->Nab]: Array comparison documentation inconsistency

From: Date: Sat, 01 Feb 2014 11:18:07 +0000
Subject: Doc #60688 [Opn->Nab]: Array comparison documentation inconsistency
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-10927@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60688&edit=1 ID: 60688 Updated by: krakjoe@php.net Reported by: wolfgang dot stengel at gmx dot de Summary: Array comparison documentation inconsistency -Status: Open +Status: Not a bug Type: Documentation Problem Package: Documentation problem Operating System: Debian PHP Version: 5.3.8 Block user comment: N Private report: N New Comment: It does make sense ... <?php $a = [1=>"one", 2=>"two"]; $b = [2=>"two", 1=>"one"]; var_dump($a>$b, $a<$b, $a==$b); ?> Produces exactly what is expected from the description: bool(false) bool(false) bool(true) So marking as not a bug, if somehow I'm wrong, feel free to open it again. Noteworthy, this bug was reported for a version of PHP that is unsupported today, if there is still a discrepancy which I do not see, then it would be wise to report the bug for a stable, supported version of PHP. Thanks for taking the time to make PHP better :) Previous Comments: ------------------------------------------------------------------------ [2012-01-25 11:08:51] wolfgang dot stengel at gmx dot de I agree that this is minor and does not need to be changed in the engine. I just thought it would be nice to have a half sentence anywhere in the documentation mentioning this. Here's the script: $a=array(0 => 2, 'test' => 2); $b=array('test' => 3, 0 => 1); var_dump($a>$b, $b>$a); Both operations result in false, which makes no sense. ------------------------------------------------------------------------ [2012-01-24 23:04:06] frozenfire@php.net I'm not seeing how this minor engine quirk produces a distinguishable effect upon the result of the operation. Could you provide a test script which demonstrates that different results will be produced based on a different invocation? ------------------------------------------------------------------------ [2012-01-08 23:48:34] wolfgang dot stengel at gmx dot de Description: ------------ Comparing arrays is in the PHP manual described as "Array with fewer members is smaller, if key from operand 1 is not found in operand 2 then arrays are uncomparable, otherwise - compare value by value (see following example)" (http://www.php.net/manual/en/language.operators.comparison.php). This does not mention that the order in which the operands are compared is reversed with the > and >= operators (I think). I found this in zend_language_parser.y: T_IS_GREATER_OR_EQUAL expr { zend_do_binary_op(ZEND_IS_SMALLER_OR_EQUAL, &$$, &$3, &$1 TSRMLS_CC); } This will lead to the foreach in the transcription of the comparison code iterating over $b instead of $a in the example below. Test script: --------------- $a=array(0 => 2, 'test' => 2); $b=array('test' => 3, 0 => 1); var_dump($a>$b); Expected result: ---------------- The documentation should mention that the > and >= operators flip the arguments. Actual result: -------------- The documentation does not mention that the > and >= operators flip the arguments. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=60688&edit=1

« previous php.doc.bugs (#10927) next »