PHP Idioms and Patterns

Standardize modern PHP 8.x idioms for strict typing and PSR-12 compliance.

150|48|Updated Jan 24, 2026
One-click install
npx skills add https://github.com/irahardianto/awesome-agv --skill php-idioms-and-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: PHP Idioms and Patterns
Source: https://github.com/irahardianto/awesome-agv/tree/main/.agents/skills/php-idioms
Command: npx skills add https://github.com/irahardianto/awesome-agv --skill php-idioms-and-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you avoid non-idiomatic or fragile PHP patterns by standardizing modern PHP practices that improve type safety, immutability, and maintainability.

Core Features & Use Cases

  • Modern PHP 8.x language features: enforce strict types, use enums for domain constants, prefer readonly DTOs, and improve clarity with named arguments and match expressions.
  • Robust error handling: encourage domain exception hierarchies, avoid overly broad exception catching, and require type-safe return values.
  • Clean interfaces and dependency injection: define interfaces at consumption points and inject dependencies through constructors.
  • Consistent conventions and quality gates: align naming and autoloading with PSR-12/PSR-4, and back changes with PHPUnit/Pest plus static analysis and security checks.

Use cases include greenfield service design, refactoring legacy PHP code toward stricter typing, and improving reliability of feature modules with consistent testing, logging, and analysis.

Quick Start

Use the PHP idioms and patterns skill to refactor your PHP files to use strict types, typed DTOs, enums, domain exceptions, PSR-12 naming, and static analysis checks.

Frequently Asked Questions about PHP Idioms and Patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce strict types and use readonly DTOs in PHP 8.x?

To enforce strict types and readonly DTOs in PHP 8.x, declare strict_types at the top of files, use readonly properties for immutable data transfer objects, and follow PSR-12 conventions for safer, maintainable code.

What is the best way to handle domain exceptions in PHP applications?

Handling domain exceptions in PHP effectively involves structuring domain exception hierarchies, avoiding overly broad exception catching, and ensuring type-safe return values for robust application error management.

How do I set up PHPStan static analysis for a production PHP codebase?

Setting up PHPStan static analysis for a production PHP codebase involves integrating it into quality gates alongside PHPUnit or Pest to enforce type safety, strict typing, and reliable domain modeling.

Does this PHP idioms approach support refactoring legacy code toward stricter typing?

Yes, this PHP idioms approach supports refactoring legacy code toward stricter typing by standardizing modern PHP 8.x practices including strict types, enums, readonly DTOs, and PSR-4 autoloading compliance.

When should I use enums for domain constants in PHP?

You should use enums for domain constants in PHP when you need type-safe, immutable representations of fixed values, replacing fragile scalar constants to improve clarity and maintainability in domain modeling.

Why define interfaces at consumption points for dependency injection in PHP?

Defining interfaces at consumption points for dependency injection in PHP decouples dependencies, allowing constructors to inject type-safe implementations and produce cleaner, more maintainable application interfaces.