Php language modern
Skill fusengine/agents/plugins/php-expert/skills/php-language-modern
Use when writing or reviewing modern PHP (8.1–8.5) outside a framework — property hooks, asymmetric visibility, the pipe operator, native attributes, enums, readonly, lazy objects. Covers language features that LLMs frequently get wrong or write in a pre-8.0 style. Do NOT use for coding style/PSR/autoloading (use php-standards) or Laravel-specific syntax (use the laravel plugin).From its SKILL.md
npx -y skills add fusengine/agents --skill php-language-modernAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 22 stars22 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
4.5 KB, ~1.0k tokens by cl100k_base, as published. Nobody here has run it
Modern PHP Language (8.1 → 8.5)
Agent Workflow (MANDATORY)
Before writing PHP, use TeamCreate to spawn 3 agents:
- fuse-ai-pilot:explore-codebase - Detect the project's minimum PHP version (
composer.jsonrequire.php, CI matrix) - fuse-ai-pilot:research-expert - Verify a feature's version + syntax on php.net before using it
- mcp__context7__query-docs - Cross-check idiomatic usage
After writing, run fuse-ai-pilot:sniper for validation.
Overview
| Feature | Since | Use it for |
|---|---|---|
| Enums (backed + methods/interfaces) | 8.1 | Closed sets of values with behavior |
First-class callable syntax f(...) | 8.1 | Passing callables without strings |
| readonly properties / classes | 8.1 / 8.2 | Immutable value objects / DTOs |
#[\Override] | 8.3 | Fail-fast on broken inheritance |
Property hooks get/set | 8.4 | Computed/validated properties, no getter/setter boilerplate |
Asymmetric visibility public private(set) | 8.4 (static: 8.5) | Public read, restricted write |
Lazy objects newLazyGhost() | 8.4 | Deferred initialization in DI containers |
Pipe operator |> | 8.5 | Left-to-right data transformation chains |
clone() function + $withProperties | 8.5 | Immutable "with" updates, incl. readonly |
#[\NoDiscard] | 8.5 | Enforce return-value consumption |
Critical Rules
- Attributes, never docblock annotations - Native
#[Attribute]replaces@annotationdocblocks for routing, ORM, DI, validation. This is the #1 LLM mistake — see attributes-over-docblocks.md. - Check the target PHP version first - Never emit 8.5 syntax on an 8.1 project. Read
composer.jsonrequire.phpbefore choosing a feature. - Prefer enums over class constants for closed value sets — they carry type safety and methods.
- Prefer
readonly+ property hooks over hand-written getters/setters — less boilerplate, enforced immutability. declare(strict_types=1);at the top of every file.
Architecture
src/
├── Enum/
│ └── Status.php # backed enum + interface + methods
├── ValueObject/
│ └── Money.php # readonly class, clone() with $withProperties
└── Model/
└── User.php # property hooks, asymmetric visibility
→ See modern-class.md for complete working code
Reference Guide
Concepts
| Topic | Reference | When to Consult |
|---|---|---|
| PHP 8.5 features | php-85-features.md | Pipe operator, clone(), #[\NoDiscard], static aviz |
| PHP 8.4 features | php-84-features.md | Property hooks, aviz, lazy objects, #[\Deprecated] |
| 8.1–8.3 baseline | php-81-83-baseline.md | Enums, readonly, fibers, #[\Override] |
| Attributes vs docblocks | attributes-over-docblocks.md | Any metadata: routing, ORM, DI, validation |
Templates
| Template | When to Use |
|---|---|
| modern-class.md | Writing a new class the modern way |
Best Practices
DO
- Read
require.phpbefore picking a feature version - Use enums with interfaces + methods for stateful value sets
- Use property hooks for validation/computation instead of magic
__get - Use the pipe operator to flatten nested calls (8.5+)
DON'T
- Write
@Route/@ORM\Columndocblock annotations — use attributes - Emit 8.4/8.5 syntax without confirming the project supports it
- Hand-roll getters/setters when hooks or
readonlyfit - Guess a feature's version — verify on php.net
What ships with it: 6 files
15.0 KB alongside SKILL.md
references/
- attributes-over-docblocks.md2.7 KB
- php-81-83-baseline.md3.0 KB
- php-84-features.md2.9 KB
- php-85-features.md3.0 KB
- templates/modern-class.md3.4 KB
- .gitkeep0 B