php-best-practices
Skill2 starsChanged 3 months agoMITView on GitHub
PHP 8.x modern patterns, PSR standards, and SOLID principles. Use when reviewing PHP code, checking type safety, auditing code quality, or ensuring PHP best practices. Triggers on "review PHP", "check PHP code", "audit PHP", or "PHP best practices".
4 other projects use a version of this.
Adopted by
Most recently taken up by
- kabudu/engineering-agent-skillstheir own version, first seen Nov 1, 2026
- davidanthonyn/claude-skillsword for word, first seen Oct 20, 2026
- kazakevic/claude-skillstheir own version, first seen Oct 11, 2026
- mduongvandinh/ai-best-practices-skillstheir own version, first seen Feb 19, 2026
Other versions4 projects use a version of this.
Word for word · 1
- davidanthonyn/claude-skills★ 0100% same
Edited · 0
None found.
Wrote their own version · 3
- mduongvandinh/ai-best-practices-skills★ 18same name
- kabudu/engineering-agent-skills★ 3same name
- kazakevic/claude-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository53 other files it gives its agents.
- instructions/AGENTS.mdAGENTS.md
- skills/software-development/php-best-practices/AGENTS.mdAGENTS.md
- instructions/CLAUDE.mdCLAUDE.md
- architecture-designerSkill
- caveman-commitSkill
- caveman-compressSkill
- cavemanSkill
- conventional-commitSkill
- youtube-contentSkill
- agentkit-skill-authoringSkill
- skill-orchestrationSkill
- analogical-thinkingSkill
- investigateSkill
- ponytailSkill
- systematic-debuggingSkill
- mermaid-diagramsSkill
- feature-forgeSkill
- find-skillsSkill
- impeccableSkill
- javascript-proSkill
- legacy-modernizerSkill
- migrationSkill
- no-ai-slopSkill
- olakunlevpn-filament-skillsSkill
- clickupSkill
- clickup-tweak-workflowSkill
- git-advancedSkill
- local-wikiSkill
- mr-reviewSkill
- php-proSkill
- doxSkill
- improveSkill
- openspecSkill
- scrutinizeSkill
- systems-thinkingSkill
- tweakSkill
- tweak-workflowSkill
- prompt-engineerSkill
- laravel-best-practicesSkill
- pest-testingSkill
- security-audit-lightSkill
- security-best-practicesSkill
- spatie-javascriptSkill
- spatie-laravel-phpSkill
- spatie-securitySkill
- spatie-version-controlSkill
- tailwindcss-developmentSkill
- test-driven-developmentSkill
- sql-proSkill
- typescript-proSkill
- ui-ux-pro-maxSkill
- vue-expert-jsSkill
- vue-expertSkill
The file
We split this skill into the rules it gives an agent
4 rules. 0 are common, 3 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 3 edited versions we read keep these.
3
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 19
Check composer.json for the required PHP version:
- Distinctive: line 42
Only suggest features available in the detected version: If the user asks about upgrading or newer features, mention what becomes available …
- Distinctive: line 225
When auditing code, output findings in this format:
- Distinctive: line 240
Read individual rule files for detailed explanations:
“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
PHP Best Practices
Modern PHP 8.x patterns, PSR standards, type system best practices, and SOLID principles. Contains 51 rules for writing clean, maintainable PHP code.
Step 1: Detect PHP Version
Always check the project's PHP version before giving any advice. Features vary significantly across 8.0 - 8.5. Never suggest syntax that doesn't exist in the project's version.
Check composer.json for the required PHP version:
{ "require": { "php": "^8.1" } } // -> 8.1 rules and below
{ "require": { "php": "^8.3" } } // -> 8.3 rules and below
{ "require": { "php": ">=8.4" } } // -> 8.4 rules and belowAlso check the runtime version:
php -v # e.g. PHP 8.3.12Feature Availability by Version
| Feature | Version | Rule Prefix | |
| Union types, match, nullsafe, named args, constructor promotion, attributes | 8.0+ | type-, modern- | |
| Enums, readonly properties, intersection types, first-class callables, never, fibers | 8.1+ | modern- | |
| Readonly classes, DNF types, true/false/null standalone types | 8.2+ | modern- | |
Typed class constants, #[\Override], json_validate() | 8.3+ | modern- | |
Property hooks, asymmetric visibility, #[\Deprecated], new without parens | 8.4+ | modern- | |
| Pipe operator ` | >` | 8.5+ | modern- |
Only suggest features available in the detected version. If the user asks about upgrading or newer features, mention what becomes available at each version.
When to Apply
Reference these guidelines when:
- Writing or reviewing PHP code
- Implementing classes and interfaces
- Using PHP 8.x modern features
- Ensuring type safety
- Following PSR standards
- Applying design patterns
Rule Categories by Priority
| Priority | Category | Impact | Prefix | Rules |
| 1 | Type System | CRITICAL | type- | 9 |
| 2 | Modern PHP Features | CRITICAL | modern- | 16 |
| 3 | PSR Standards | HIGH | psr- | 6 |
| 4 | SOLID Principles | HIGH | solid- | 5 |
| 5 | Error Handling | HIGH | error- | 5 |
| 6 | Performance | MEDIUM | perf- | 5 |
| 7 | Security | CRITICAL | sec- | 5 |
Quick Reference
1. Type System (CRITICAL) — 9 rules
type-strict-mode- Declare strict types in every filetype-return-types- Always declare return typestype-parameter-types- Type all parameterstype-property-types- Type class propertiestype-union-types- Use union types effectivelytype-intersection-types- Use intersection typestype-nullable-types- Handle nullable types properlytype-void-never- Use void/never for appropriate return typestype-mixed-avoid- Avoid mixed type when possible
2. Modern PHP Features (CRITICAL) — 16 rules
8.0+:
modern-constructor-promotion- Constructor property promotionmodern-match-expression- Match over switchmodern-named-arguments- Named arguments for claritymodern-nullsafe-operator- Nullsafe operator (?->)modern-attributes- Attributes for metadata
8.1+:
modern-enums- Enums instead of constantsmodern-enums-methods- Enums with methods and interfacesmodern-readonly-properties- Readonly for immutable datamodern-first-class-callables- First-class callable syntaxmodern-arrow-functions- Arrow functions (7.4+, pairs well with 8.1 features)
8.2+:
modern-readonly-classes- Readonly classes
8.3+:
modern-typed-constants- Typed class constants (const string NAME = 'foo')modern-override-attribute-#[\Override]to catch parent method typos
8.4+:
modern-property-hooks- Property hooks replacing getters/settersmodern-asymmetric-visibility-public private(set)for controlled access
8.5+:
modern-pipe-operator- Pipe operator (|>) for functional chaining
3. PSR Standards (HIGH) — 6 rules
psr-4-autoloading- Follow PSR-4 autoloadingpsr-12-coding-style- Follow PSR-12 coding stylepsr-naming-classes- Class naming conventionspsr-naming-methods- Method naming conventionspsr-file-structure- One class per filepsr-namespace-usage- Proper namespace usage
4. SOLID Principles (HIGH) — 5 rules
solid-srp- Single Responsibility: one reason to changesolid-ocp- Open/Closed: extend, don't modifysolid-lsp- Liskov Substitution: subtypes must be substitutablesolid-isp- Interface Segregation: small, focused interfacessolid-dip- Dependency Inversion: depend on abstractions
5. Error Handling (HIGH) — 5 rules
error-custom-exceptions- Create specific exceptions for different errorserror-exception-hierarchy- Organize exceptions into meaningful hierarchyerror-try-catch-specific- Catch specific exceptions, not generic \Exceptionerror-finally-cleanup- Use finally for guaranteed resource cleanuperror-never-suppress- Never use @ error suppression operator
6. Performance (MEDIUM) — 5 rules
perf-avoid-globals- Avoid global variables, use dependency injectionperf-lazy-loading- Defer expensive operations until neededperf-array-functions- Use native array functions over manual loopsperf-string-functions- Use native string functions over regexperf-generators- Use generators for large datasets
7. Security (CRITICAL) — 5 rules
sec-input-validation- Validate and sanitize all external inputsec-output-escaping- Escape output based on context (HTML, JS, URL)sec-password-hashing- Use password_hash/verify, never MD5/SHA1sec-sql-prepared- Use prepared statements for all SQL queriessec-file-uploads- Validate file type, size, name; store outside web root
Essential Guidelines
For detailed examples and explanations, see the rule files:
- type-strict-mode.md - Strict types declaration
- modern-constructor-promotion.md - Constructor property promotion
- modern-enums.md - PHP 8.1+ enums with methods
- solid-srp.md - Single responsibility principle
Key Patterns (Quick Reference)
<?php
declare(strict_types=1);
// 8.0+ Constructor promotion + readonly (8.1+)
class User
{
public function __construct(
public readonly string $id,
private string $email,
) {}
}
// 8.1+ Enums with methods
enum Status: string
{
case Active = 'active';
case Inactive = 'inactive';
public function label(): string
{
return match($this) {
self::Active => 'Active',
self::Inactive => 'Inactive',
};
}
}
// 8.0+ Match expression
$result = match($status) {
'pending' => 'Waiting',
'active' => 'Running',
default => 'Unknown',
};
// 8.0+ Nullsafe operator
$country = $user?->getAddress()?->getCountry();
// 8.3+ Typed class constants + #[\Override]
class PaymentService extends BaseService
{
public const string GATEWAY = 'stripe';
#[\Override]
public function process(): void { /* ... */ }
}
// 8.4+ Property hooks + asymmetric visibility
class Product
{
public string $name { set => trim($value); }
public private(set) float $price;
}
// 8.5+ Pipe operator
$result = $input
|> trim(...)
|> strtolower(...)
|> htmlspecialchars(...);Output Format
When auditing code, output findings in this format:
file:line - [category] Description of issueExample:
src/Services/UserService.php:15 - [type] Missing return type declaration
src/Models/Order.php:42 - [modern] Use match expression instead of switch
src/Controllers/ApiController.php:28 - [solid] Class has multiple responsibilitiesHow to Use
Read individual rule files for detailed explanations:
rules/modern-constructor-promotion.md
rules/type-strict-mode.md
rules/solid-srp.mdDoes it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

