ID: 31032 Updated by: [EMAIL PROTECTED] Reported By: php dot devel at homelinkcs dot com -Status: Open +Status: Closed Bug Type: Documentation problem Operating System: Probably all PHP Version: Irrelevant New Comment:
This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. Previous Comments: ------------------------------------------------------------------------ [2004-12-09 04:42:27] php dot devel at homelinkcs dot com 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 this bug report at http://bugs.php.net/?id=31032&edit=1