From: php dot devel at homelinkcs dot com Operating system: Probably all PHP version: Irrelevant PHP Bug Type: Documentation problem Bug description: Array comparision operators doc inprecise
Description: ------------ Based on my experimentation, this description of array comparison operators, found at http://us2.php.net/manual/en/language.operators.array.php, seems terribly imprecise: $a == $b TRUE if $a and $b have the same elements. $a === $b TRUE if $a and $b have the same elements in the same order. I submit that more precise and helpful definitions would be: $a == $b TRUE if $a and $b have the same key/value pairs. $a === $b TRUE if $a and $b have the same key/value pairs, in the same order, and of the same types. I based my conclusions on the script below, tested on Linux using PHP 4.3.4 and PHP 5.0.2. Reproduce code: --------------- <?php // Equality operator: // Key/value pairs must be same var_dump(array(1,2) == array(1=>1,2=>2)); // False // Order can be different var_dump(array(1,2) == array(1=>2,0=>1)); // True // And types can be different var_dump(array(1,2) == array('1','2e0')); // True // Identity operator: // Key/value pairs must be same var_dump(array(1,2) === array(1=>1,2=>2)); // False // Order must be same var_dump(array(1,2) === array(1=>2,0=>1)); // False // And types must be same var_dump(array(1,2) === array('1',2)); // False var_dump(array(1,2) === array(1,'2e0')); // False ?> Expected result: ---------------- Taking the manual's descriptions at face-value, I would have expected the script to return: bool(true) (elements are same, only keys are different) bool(true) bool(true) bool(true) (elements are in same order, only keys are different) bool(false) bool(true) (elements are in same order, only types, which the manual doesn't refer to in discussion of arrays, are different) bool(true) Actual result: -------------- The script actually returns (as explained in the comments): bool(false) bool(true) bool(true) bool(false) bool(false) bool(false) bool(false) -- Edit bug report at http://bugs.php.net/?id=31032&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31032&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=31032&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=31032&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=31032&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=31032&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=31032&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=31032&r=needscript Try newer version: http://bugs.php.net/fix.php?id=31032&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=31032&r=support Expected behavior: http://bugs.php.net/fix.php?id=31032&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=31032&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=31032&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=31032&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31032&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=31032&r=dst IIS Stability: http://bugs.php.net/fix.php?id=31032&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=31032&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=31032&r=float MySQL Configuration Error: http://bugs.php.net/fix.php?id=31032&r=mysqlcfg