1---2name: php3description: Write solid PHP avoiding type juggling traps, array quirks, and common security pitfalls.4---56## Quick Reference78| Topic | File |9|-------|------|10| Loose typing, ==, ===, type juggling, strict_types | `types.md` |11| Associative arrays, iteration, array functions | `arrays.md` |12| Traits, interfaces, visibility, late static binding | `oop.md` |13| Encoding, interpolation, heredoc, regex | `strings.md` |14| Exceptions, error handling, @ operator | `errors.md` |15| SQL injection, XSS, CSRF, input validation | `security.md` |16| PHP 8+ features, attributes, named args, match | `modern.md` |1718## Critical Rules1920- `==` coerces types: `"0" == false` is true — always use `===` for strict comparison21- `in_array($val, $arr)` uses loose comparison — pass `true` as third param for strict22- `strpos()` returns 0 for match at start — use `=== false` not `!strpos()`23- Never concatenate SQL — use prepared statements with PDO24- `htmlspecialchars($s, ENT_QUOTES)` all output — prevents XSS25- `isset()` returns false for null — use `array_key_exists()` to check key exists26- `foreach ($arr as &$val)` — unset `$val` after loop or last ref persists27- `static::` late binding vs `self::` early binding — `static` respects overrides28- `@` suppresses errors — avoid, makes debugging impossible29- Catch `Throwable` for both `Error` and `Exception` — PHP 7+30- `declare(strict_types=1)` per file — enables strict type checking31- `strlen()` counts bytes — use `mb_strlen()` for UTF-8 character count32- Objects pass by reference-like handle — clone explicitly with `clone $obj`33- `array_merge()` reindexes numeric keys — use `+` operator to preserve keys