Back to Skills

php-best-practices

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".

43stars5forksUpdated 6/15/2026

Security Assessment

Low Risk(70/100)

Detected risks:

Secret Exposure([rules/modern-named-arguments.md] password =, [rules/sec-password-hashing.md] password =)
Security Score70/100

About php-best-practices

The PHP Best Practices skill provides comprehensive guidance for writing modern, maintainable PHP code following PHP 8.x standards. It addresses the common challenge of keeping PHP codebases aligned with evolving language features, PSR standards, and SOLID principles. By detecting the project's PHP version first, it ensures recommendations are compatible with the specific PHP version in use (8.0 through 8.5), preventing suggestions of unavailable syntax or features.

This skill contains 51 rules organized into 7 priority-based categories: Type System (9 rules), Modern PHP Features (16 rules), PSR Standards (6 rules), SOLID Principles (5 rules), Error Handling (5 rules), Performance (5 rules), and Security (5 rules). It covers critical areas like strict typing, constructor property promotion, match expressions, enums, readonly properties and classes, attributes, nullsafe operators, and version-specific features like property hooks in 8.4 and the pipe operator in 8.5.

The skill is designed for PHP developers conducting code reviews, implementing new features, refactoring legacy code, or ensuring code quality and type safety. It's particularly valuable for teams upgrading between PHP 8.x versions, as it provides clear feature availability tables showing which modern constructs are available at each version. Whether you're auditing existing code or writing new implementations, this skill helps enforce best practices while respecting version constraints.

FAQ

How does this skill handle different PHP versions?

The skill always checks the project's PHP version first by examining composer.json and runtime version. It provides a feature availability table showing which modern features are available in versions 8.0 through 8.5, ensuring recommendations match the detected version. It never suggests syntax unavailable in your version.

What are the priority levels and what do they mean?

Rules are organized into 7 categories with priority levels: CRITICAL (Type System, Modern PHP Features, Security), HIGH (PSR Standards, SOLID Principles, Error Handling), and MEDIUM (Performance). Higher priority rules have greater impact on code safety, maintainability, and correctness.

When should I trigger this skill?

Use this skill when writing or reviewing PHP code, implementing classes and interfaces, ensuring type safety, following PSR standards, or applying design patterns. Trigger phrases include 'review PHP', 'check PHP code', 'audit PHP', or 'PHP best practices'.

Does this skill cover all PSR standards?

The skill includes 6 rules covering key PSR standards for code structure, naming conventions, and formatting. It focuses on the most impactful standards for code quality and maintainability in modern PHP development.

What modern PHP 8.x features are included?

The skill covers 16 modern PHP features including constructor property promotion, match expressions, enums with methods, readonly properties and classes, attributes, nullsafe operators, first-class callables, typed constants, the Override attribute, property hooks (8.4), and the pipe operator (8.5).

All Files

57 files
rules/type-union-types.md2.0 KB
View
rules/perf-lazy-loading.md2.6 KB
View
rules/psr-file-structure.md5.0 KB
View
rules/type-intersection-types.md2.6 KB
View
rules/type-return-types.md1.8 KB
View
rules/type-strict-mode.md4.6 KB
View
rules/error-never-suppress.md2.4 KB
View
rules/error-finally-cleanup.md2.6 KB
View
metadata.json2.9 KB
View
rules/error-try-catch-specific.md2.5 KB
View
rules/modern-match-expression.md3.7 KB
View
rules/modern-readonly-classes.md3.3 KB
View
AGENTS.md20.8 KB
View
README.md2.2 KB
View
rules/_template.md1.0 KB
View
rules/modern-arrow-functions.md3.3 KB
View
rules/_sections.md2.0 KB
View
rules/error-custom-exceptions.md3.5 KB
View
rules/modern-asymmetric-visibility.md2.7 KB
View
rules/error-exception-hierarchy.md3.4 KB
View
rules/modern-attributes.md3.9 KB
View
rules/modern-enums.md6.8 KB
View
rules/modern-pipe-operator.md2.6 KB
View
rules/perf-avoid-globals.md2.1 KB
View
rules/sec-file-uploads.md3.6 KB
View
rules/solid-isp.md6.7 KB
View
rules/type-nullable-types.md2.5 KB
View
rules/modern-constructor-promotion.md4.1 KB
View
rules/modern-first-class-callables.md4.5 KB
View
rules/modern-property-hooks.md3.1 KB
View
rules/perf-generators.md2.8 KB
View
rules/psr-4-autoloading.md2.8 KB
View
rules/modern-enums-methods.md4.7 KB
View
rules/modern-override-attribute.md2.6 KB
View
rules/perf-array-functions.md2.2 KB
View
rules/psr-12-coding-style.md4.7 KB
View
rules/psr-naming-methods.md5.7 KB
View
rules/solid-dip.md7.0 KB
View
rules/type-mixed-avoid.md3.0 KB
View
rules/modern-named-arguments.md3.1 KB
View
rules/modern-readonly-properties.md3.1 KB
View
rules/perf-string-functions.md2.0 KB
View
rules/psr-namespace-usage.md4.9 KB
View
rules/sec-password-hashing.md2.6 KB
View
rules/solid-srp.md6.7 KB
View
rules/modern-nullsafe-operator.md3.6 KB
View
rules/modern-typed-constants.md2.3 KB
View
rules/psr-naming-classes.md3.6 KB
View
rules/sec-sql-prepared.md2.6 KB
View
rules/sec-input-validation.md2.6 KB
View
rules/solid-lsp.md6.5 KB
View
rules/type-parameter-types.md1.8 KB
View
SKILL.md8.1 KB
View
rules/sec-output-escaping.md2.1 KB
View
rules/solid-ocp.md6.8 KB
View
rules/type-property-types.md1.9 KB
View
rules/type-void-never.md2.9 KB
View

Install php-best-practices

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill