home / skills / hoangnguyen0403 / agent-skills-standard / language
This skill enforces modern PHP standards and typing discipline to improve code quality, readability, and maintainability across projects.
npx playbooks add skill hoangnguyen0403/agent-skills-standard --skill languageReview the files below or copy the command above to add this skill to your agents.
---
name: PHP Language Standards
description: Core PHP language standards and modern 8.x features.
metadata:
labels: [php, language, 8.x]
triggers:
files: ['**/*.php']
keywords: [declare, readonly, match, constructor, promotion, types]
---
# PHP Language Standards
## **Priority: P0 (CRITICAL)**
## Structure
```text
src/
└── {Namespace}/
└── {Class}.php
```
## Implementation Guidelines
- **Strict Typing**: Declare `declare(strict_types=1);` at file top.
- **Type Hinting**: Apply scalar hints and return types to all members.
- **Modern Types**: Use Union (`string|int`) and Intersection types.
- **Read-only**: Use `readonly` for immutable properties.
- **Constructor Promotion**: Combine declaration and assignment in `__construct`.
- **Match Expressions**: Prefer `match` over `switch` for value returns.
- **Named Arguments**: Use for readability in optional parameters.
## Anti-Patterns
- **No Type Context**: Avoid functions without return or parameter types.
- **Sloppy Comparison**: **No ==**: Use `===` for strict comparison.
- **Legacy Syntax**: **No switch**: Use `match` for simple value mapping.
- **Global Scope**: **No Globals**: Never define logic in global namespace.
## References
- [Modern PHP Patterns](references/implementation.md)
This skill codifies core PHP language standards focused on modern PHP 8.x features and safe, maintainable code. It provides concrete rules for file layout, typing, modern syntax, and common anti-patterns to ensure consistent, robust PHP code across projects.
The skill inspects PHP source structure and declarations, enforcing strict typing, type hints, and modern type constructs like unions and readonly properties. It flags legacy constructs (loose comparisons, switch statements, global-scope logic) and recommends contemporary alternatives such as match expressions and named arguments for clarity.
What file layout should I use for classes?
Use src/{Namespace}/{Class}.php so each class lives in a namespaced file that matches its path.
Why prefer match over switch?
match is expression-based, safer for returning values, and avoids fall-through bugs common with switch.