Who knows the difference between == and === on PHP? Well, I already knew and still, fell on a trap that I done myself… I was working on a method that receives “on” and “off” and returns 1 and 0 or  “on” and “off”. When I needed to compare the return var with a value, I forgot the importance of the difference between the signs.

I was doing:

Briefly, the difference between == and === is that beyond value comparison, it also compares the data type.

Considering the affirmative above, the correct code was:

This is the right way because when $destaque was with 0 (integer), it considered that $destaque == “on” is TRUE, but I was expecting FALSE.

Observe this table on PHP manual:
http://php.net/manual/en/types.comparisons.php

Lesson learned???

Leave a Reply

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

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.