note 104831 added to language.operators.comparison
| From: | CuongHuyTo at osu1 dot php dot net | Date: | Sun, 10 Jul 2011 01:06:28 +0000 |
| Subject: | note 104831 added to language.operators.comparison | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-181388@lists.php.net to get a copy of this message | ||
Please be explicit in the table "Comparison with Various Types". There should be one table
for each of the comparison operators (9 operators ===, ==, !=, !==, <>, <, >, <=,
>=), otherwise a lot of confusions would occur.
Examples of how to build such table are the specifications for functions and operator of ECMA script
262: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
Followings are some of the confusions given the unclear information in current table (PHP 5.3.3)
1) Array or Object is greater ?
In the following example, the sentence "Array is always greater" in the table is wrong.
<?php
class C {
}
$x = array();
$y = new C();
if ($x > $y) {echo 'array is greater than object';} // Nothing printed.
if ($y > $x) {echo 'object is greater than array';} // This is printed.
?>
2) Confusing string comparison
in the following example, two numeric strings cannot be compared using the trivial "<"
or ">" operator !!!
<?php
$a = "1234";
$b = "01234";
if ($a == $b) {echo 'equal';} // "equal"
if ($a === $b) {echo 'identical';} // nothing printed
if ($a < $b) {echo 'equal';} // nothing printed, as they are "equal"
if ($a > $b) {echo 'equal';} // nothing printed, as they are "equal"
?>
----
Server IP: 69.147.83.197
Probable Submitter: 213.46.130.4
----
Manual Page -- http://www.php.net/manual/en/language.operators.comparison.php
Edit -- https://master.php.net/note/edit/104831
Del: integrated -- https://master.php.net/note/delete/104831/integrated
Del: useless -- https://master.php.net/note/delete/104831/useless
Del: bad code -- https://master.php.net/note/delete/104831/bad+code
Del: spam -- https://master.php.net/note/delete/104831/spam
Del: non-english -- https://master.php.net/note/delete/104831/non-english
Del: in docs -- https://master.php.net/note/delete/104831/in+docs
Del: other reasons-- https://master.php.net/note/delete/104831
Reject -- https://master.php.net/note/reject/104831
Search -- https://master.php.net/manage/user-notes.php