Reminder to self: Don’t use == for string comparison in PHP

From SO thread

You should never use == for string comparison. === is OK.

$something = 0;
echo ('password123' == $something) ? 'true' : 'false';

Just run the above code and you’ll see why.

$something = 0;
echo ('password123' === $something) ? 'true' : 'false';

The reason is that when using ‘==’ it will try to convert the string to a number, and match it!

Now where’s the emoji for facepalm?

Similar Posts:

Tagged ,

Leave a Reply

Your email address will not be published. Required fields are marked *