note 38139 added to language.operators.comparison
| From: | jwhiting at hampshire dot edu | Date: | Tue, 09 Dec 2003 20:31:50 +0000 |
| Subject: | note 38139 added to language.operators.comparison | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-61702@lists.php.net to get a copy of this message | ||
note: the behavior below is documented in the appendix K about type comparisons, but since it is
somewhat buried i thought i should raise it here for people since it threw me for a loop until i
figured it out completely.
just to clarify a tricky point about the == comparison operator when dealing with strings and
numbers:
('some string' == 0) returns TRUE
however, ('123' == 0) returns FALSE
also note that ((int) 'some string') returns 0
and ((int) '123') returns 123
the behavior makes senes but you must be careful when comparing strings to numbers, e.g. when
you're comparing a request variable which you expect to be numeric. its easy to fall into the
trap of:
if ($_GET['myvar']==0) dosomething();
as this will dosomething() even when $_GET['myvar'] is 'some string' and clearly
not the value 0
i was getting lazy with my types since php vars are so flexible, so be warned to pay attention to
the details...
----
Manual Page -- http://www.php.net/manual/en/language.operators.comparison.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38139
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38139&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38139&report=yes
Search -- http://master.php.net/manage/user-notes.php