Explain the 'Type Juggling' vulnerabilities and how strict typing (declare(strict_types=1)) mitigates specific security risks.

Last updated 15 June 2026

  • Type juggling is PHP's automatic type coercion in loose == comparisons. For example, "0e123" == "0e456" is true (magic hashes), which can bypass hash or password checks.

  • declare(strict_types=1) makes argument and return type mismatches throw a TypeError instead of silently coercing. It does not change how == behaves.

  • Full defense: use === for comparisons, and use hash_equals() or password_verify() for hashes and tokens.

  • https://0xkratos.medium.com/php-type-juggling-vulnerabilities-how-attackers-exploit-loose-comparisons-e4e0c78ec9e6
All PHP interview questions