← ClaudeAtlas

php-8x-featureslisted

PHP 8.0 → 8.3 language features and when to use them. Use when the project's declared PHP floor permits 8.x syntax, when reviewing whether a 7.4-and-up library can adopt an 8.x idiom conditionally, when designing a public API that should leverage attributes / enums / readonly for type safety, or when working through migration from a 7.4-style class to its 8.x equivalent. Covers match / nullsafe / named arguments / constructor promotion / attributes / readonly properties / enums / intersection types / new in initializers / readonly classes / DNF types / typed class constants — with per-feature min-PHP markers so library authors know what their composer constraint permits. Counterpart to php-modern-pro (which is 7.4-baseline). Not for everyday business logic — load when picking between two valid idioms or designing API shape.
hmj1026/dhpk · ★ 1 · AI & Automation · score 72
Install: claude install-skill hmj1026/dhpk
# PHP 8.x features — additive on top of 7.4 This skill assumes you've read or have access to `modules/php-7.4/skills/php-modern-pro/SKILL.md`. That skill covers 7.4 baseline + dual-version-floor library patterns. This skill adds the 8.x features and the **library-author rule** for each: when can you use it unconditionally, when must you gate it. > Mental model: every 8.x feature is **syntax**, not runtime. There is > no polyfill. If the constraint floor is 7.x, the code is a parse error > on 7.x runtimes — you cannot wrap it in a `function_exists` check. --- ## 8.0 features ### `match` expression — min PHP 8.0 ```php $label = match ($code) { 100, 200, 300 => 'success', 404 => 'not found', 500 => 'server error', default => 'unknown', }; ``` - Strict comparison (`===`), unlike `switch`'s loose `==`. - Each arm is an *expression* — returns a value. The whole `match` evaluates to that value. - Missing default + unhandled value throws `UnhandledMatchError`. This catches bugs that `switch`'s silent fall-through hides. - **Library rule**: gate to apps with PHP floor ≥8.0. Don't ship in a `^7.4 \|\| ^8.0` library — `switch` is the right idiom there. ### Nullsafe `?->` — min PHP 8.0 ```php $city = $user?->profile?->address?->city ?? 'unknown'; ``` - Chain stops at the first `null`; the whole expression evaluates to `null`. Pair with `??` for a default. - Only works on method/property access, not array indexing (`$arr['k']?-