What is the difference between == and === in PHP, and how does type juggling work?
=== compares type and value. == converts the operands to a common type first, following rules that produce genuinely surprising results.
PHP 8 fixed the worst of it. Comparing a number to a non-numeric string used to cast the string to a number, so 0 == "foo" was true — a real authentication bypass in the wild. Since PHP 8, the number is cast to a string instead, so that comparison is now false.
What still catches people:
"1" == "01"istrue— two numeric strings are compared as numbers."10" == "1e1"istrue, for the same reason.null == false,0 == false, and"" == falseare alltrue.[] == falseistrue.
The practical rule: use === by default. It is not a style preference — loose comparison against user input has caused real security vulnerabilities, particularly when comparing tokens or hashes. For those, use hash_equals(), which is also timing-safe.
Note: Be ready for in_array() as a follow-up. Its third parameter enables strict comparison, and without it in_array(0, ['a','b']) behaved surprisingly on older versions.





