1---
2name: php
3slug: php
4version: 1.0.1
5description: Write solid PHP avoiding type juggling traps, array quirks, and common security pitfalls.
6metadata:
7 source: https://skillmd.com/skills/modbender/php
8 clawdbot:
9 emoji: 🐘
10 requires:
11 bins:
12 - php
13 os:
14 - linux
15 - darwin
16 - win32
17---
18
19## Quick Reference
20
21| Topic | File |
22|-------|------|
23| Loose typing, ==, ===, type juggling, strict_types | `types.md` |
24| Associative arrays, iteration, array functions | `arrays.md` |
25| Traits, interfaces, visibility, late static binding | `oop.md` |
26| Encoding, interpolation, heredoc, regex | `strings.md` |
27| Exceptions, error handling, @ operator | `errors.md` |
28| SQL injection, XSS, CSRF, input validation | `security.md` |
29| PHP 8+ features, attributes, named args, match | `modern.md` |
30
31## Critical Rules
32
33- `==` coerces types: `"0" == false` is true — always use `===` for strict comparison
34- `in_array($val, $arr)` uses loose comparison — pass `true` as third param for strict
35- `strpos()` returns 0 for match at start — use `=== false` not `!strpos()`
36- Never concatenate SQL — use prepared statements with PDO
37- `htmlspecialchars($s, ENT_QUOTES)` all output — prevents XSS
38- `isset()` returns false for null — use `array_key_exists()` to check key exists
39- `foreach ($arr as &$val)` — unset `$val` after loop or last ref persists
40- `static::` late binding vs `self::` early binding — `static` respects overrides
41- `@` suppresses errors — avoid, makes debugging impossible
42- Catch `Throwable` for both `Error` and `Exception` — PHP 7+
43- `declare(strict_types=1)` per file — enables strict type checking
44- `strlen()` counts bytes — use `mb_strlen()` for UTF-8 character count
45- Objects pass by reference-like handle — clone explicitly with `clone $obj`
46- `array_merge()` reindexes numeric keys — use `+` operator to preserve keys