note 40486 added to control-structures
| From: | freshprincecharming at yahoo dot com | Date: | Fri, 05 Mar 2004 04:30:57 +0000 |
| Subject: | note 40486 added to control-structures | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-66285@lists.php.net to get a copy of this message | ||
Remember that PHP is type free.
That means that if you do a comparison with the == operator on 'this string' and the
integer value 0, they WILL MATCH! For example:
if ('some string' == 0)
// THIS WILL MATCH!
To avoid this situation, make sure you use the === operator, or cast your variables where needed,
like so:
if (string($key) == 'some string')
//do something;
I just spent 20 hours debugging my code because my variable $key was 0 and it evaluated the
expression ($key == 'some string') as true!
Hope this helps someone.
----
Manual Page -- http://www.php.net/manual/en/control-structures.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+40486
Delete -- http://master.php.net/manage/user-notes.php?action=delete+40486&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+40486&report=yes
Search -- http://master.php.net/manage/user-notes.php