Glossary

Type Juggling

Type juggling is PHP's implicit automatic conversion of types during operations between different types. PHP is dynamically typed: "5" + 3 = 8 (the string becomes a number). Convenient, but a source of subtle bugs.

Classic traps

// Loose comparison ==
0    == "foo"  // true (before PHP 8: "foo" → 0)
0    == ""     // true (before PHP 8)
"1"  == "01"   // true
100  == "1e2"  // true
null == false  // true

// PHP 8 fixed: non-numeric strings compare as strings
0 == "foo"  // false in PHP 8+

The rule

Always use strict comparison === and !== — it checks both type and value. Enable declare(strict_types=1).

var_dump vs print_r

var_dump() shows type and value — indispensable when debugging type-related issues.