|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-01-08 23:48 UTC] 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. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 19 20:00:01 2025 UTC |
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.