Php Idioms
This skill covers idiomatic PHP 8.x development, emphasizing strict typing, immutable data structures via readonly classes and enums, and domain-driven error handling. Learn named arguments, match expressions, constructor injection, and PSR-12 naming conventions alongside static analysis tools like PHPStan and Psalm.
PHP Idioms teaches modern PHP 8.x patterns for type-safe, immutable, and framework-agnostic code.
AI-generated summary based on this skill's SKILL.md
Decision gist · record as of 2026-07-17
PHP Idioms teaches modern PHP 8.x patterns for type-safe, immutable, and framework-agnostic code. This skill covers idiomatic PHP 8.x development, emphasizing strict typing, immutable data structures via readonly classes and enums, and domain-driven error handling. Learn named arguments, match expressions, constructor injection, and PSR-12 naming conventions alongside static analysis tools like PHPStan and Psalm.
Use it when
- Php Idioms covers PSR-12 standards for class names (PascalCase), method names (camelCase), constants (UPPER_SNAKE_CASE).
- Php Idioms recommends PHPStan and Psalm for static type checking, and PHP CS Fixer for code formatting.
Verify before relying
Read SKILL.md below before installing (1 file). Open directory: indexed for reading, not audited.
Install
irahardianto/awesome-agv/php-idioms · repository language: JavaScript
Open directory. Skills are indexed for reading, not audited. Review a skill's body before installing it.
Frequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
What modern PHP 8.x idioms and best practices should I follow?
Php Idioms teaches strict typing with declare(strict_types=1), named arguments for clarity, match expressions over switch statements, and constructor injection for dependency management. Use readonly classes and enums for immutable data, leverage union and intersection types, and adopt PSR-12 naming conventions. These patterns make code type-safe, testable, and maintainable across PHP 8.x projects.
How do I implement PSR-12 compliant naming and structure?
Php Idioms covers PSR-12 standards for class names (PascalCase), method names (camelCase), constants (UPPER_SNAKE_CASE), and file organization. Apply these conventions consistently across namespaces, use PHP CS Fixer to automate formatting, and configure your IDE to enforce rules. This ensures your codebase remains readable and aligns with community standards.
What static analysis and formatting tools should I set up?
Php Idioms recommends PHPStan and Psalm for static type checking, and PHP CS Fixer for code formatting. Configure these tools in your CI/CD pipeline to catch type errors, unused variables, and style violations before deployment. Combined with PHPUnit or Pest for testing, they form a robust quality gate for PHP projects.
How can I design immutable DTOs and domain exceptions in PHP?
Php Idioms teaches readonly classes and enums to enforce immutability in Data Transfer Objects. Design domain exceptions as a hierarchy with specific exception classes for different error scenarios. Use constructor promotion and strict typing to ensure DTOs are type-safe and exceptions carry meaningful context for error handling.
What are PHP match expressions and how do they differ from switch?
Php Idioms explains that PHP 8.x match expressions are stricter than switch statements—they require exhaustive cases, return values directly, and use strict (===) comparison by default. Match is ideal for pattern matching and cleaner syntax when mapping inputs to outputs, reducing boilerplate and potential bugs.
How do I write testable PHP with proper dependency injection?
Php Idioms covers constructor injection as the primary pattern: accept dependencies as constructor parameters typed with interfaces, not concrete classes. This decouples your code, enables easy mocking in tests, and follows SOLID principles. Combine with PHPUnit or Pest frameworks to verify behavior without tight coupling.
SKILL.md
Rendered from the published skill. Quoted content, verbatim.
PHP Idioms and Patterns
Modern PHP (8.x) rewards type safety, immutability, and framework-agnostic design. Lean into typed properties, enums, and readonly classes. Idiomatic PHP = strict types, PSR-compliant, well-tested.
> Scope: PHP coding idioms. Test naming: .agents/rules/testing-strategy.md. Logging: @.agents/skills/logging-implementation/SKILL.md.
Modern PHP Features (8.x)
-
declare(strict_types=1)— always, every file. -
Enums for domain constants:
php enum Priority: string { case Low = 'low'; case Medium = 'medium'; case High = 'high'; } -
Readonly classes for immutable DTOs:
php readonly class CreateTaskRequest { public function __construct( public string $title, public Priority $priority, ) {} } -
Named arguments for clarity:
php $task = new Task(title: 'Deploy fix', priority: Priority::High); -
Match expressions over switch:
php $score = match($priority) { Priority::Low => 1, Priority::Medium => 5, Priority::High => 10, };
Error Handling
1.
(truncated - see the full file via the links below)
File tree — 1 file
.agents/skills/php-idioms/SKILL.md
Let your AI agent find skills like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 56,283 agent skills by what they can do, searchable in plain language.
wish › “Learn modern PHP 8.x idioms and best practices for type-safe code”
Give your agent the search over MCP, or paste the wish link into any chat. No install? Search from any chat →
Related skills
PHP Specialist guides you through modern PHP 8.x development with language features like enums, readonly properties, and match expressions. It covers the complete toolchain: PSR interoperability, Composer dependency management, static analysis configuration, and coding standards enforcement. Apply it whenever you're authoring, reviewing, or refactoring PHP code to ensure type safety and architectural correctness.
Java Idioms covers modern language features and conventions for Java 17+ LTS, emphasizing records for immutable data, sealed classes for type-safe hierarchies, and pattern matching in switch expressions. The skill guides constructor injection, domain-specific exception handling, and testing with JUnit 5 and Mockito, alongside static analysis tooling to enforce code quality before commit.
Learn Laravel's idiomatic approach to building maintainable applications through Eloquent query scopes, service-oriented architecture, and Form Request validation. Covers testing with Pest, code formatting with Pint, and static analysis via PHPStan to enforce framework best practices.
PHP Pro is a senior-level specialist for modern PHP development with Laravel, Symfony, and PHP 8.3+. It enforces strict typing, dependency injection, and PSR compliance while generating typed DTOs, services, controllers, and comprehensive tests. Every implementation passes PHPStan level 9 and PHPUnit/Pest coverage thresholds before delivery.
PHP guides you through modern language conventions, strict type declarations, and contemporary idioms for PHP 8.5+. It covers naming standards, type system rules, enumerations, class design patterns, and functional programming constructs to keep your code explicit and maintainable.
PHP Rules enforces coding standards covering style, frameworks, patterns, security, and testing. It guides PSR-12 compliance, modern PHP 8.1+ syntax, Laravel and Symfony conventions, Eloquent and Doctrine patterns, and error handling best practices.
More skills php-expert (Apache-2.0) · php (MIT) · typescript-idioms (MIT) · Php Modernization (NOASSERTION) · Elixir Idioms (MIT) · ruby (MIT) · Php Modernization (NOASSERTION)