php-best-practices

Installation
Summary

51 rules for writing clean, type-safe, modern PHP 8.x code aligned with PSR standards and SOLID principles.

  • Covers 7 rule categories: type system, modern PHP features (8.0–8.5), PSR standards, SOLID principles, error handling, performance, and security
  • Version-aware guidance that detects PHP version from composer.json and runtime, recommending only features available in the target version
  • Organized by priority: type safety and security are critical; modern features and SOLID principles are high-impact
  • Includes quick reference patterns for constructor promotion, enums, match expressions, nullsafe operators, property hooks, and pipe operators
SKILL.md

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 below

Also check the runtime version:

php -v   # e.g. PHP 8.3.12
Related skills

More from asyrafhussin/agent-skills

Installs
1.6K
GitHub Stars
37
First Seen
Jan 24, 2026