PHP Coding Practices
Application skill for PHP style learning (from the archived awesome-guidelines style capsules). For Laravel/Symfony/WordPress stack patterns, load stack capsules under skills/*-foundation.
Core Principle
PHP readability is PSR mechanical layout plus strict typed APIs, side-effect-free autoload files, identical comparison, injected dependencies.
When to Use / NOT
- PHP application/library source, Composer packages, PHPCS/Pint/PHP-CS-Fixer CI.
- Reviewing namespaces, types, comparison, class design.
NOT when:
- Non-PHP code.
- Generated stubs (PHPUnit mocks, protobuf), validate generator config instead.
- CMS-specific rules (WordPress/Drupal), use stack capsules under
skills/*-foundation.
Workflow
- Format & layout, PSR-12 indent, braces, imports, LF endings (
php-style-formatting-layout.md).
- Files & namespaces, PSR-4 side-effect-free files, PascalCase/camelCase (
php-style-files-namespaces.md).
- Types,
strict_types, hints, ===, ?? (php-style-types-comparisons.md).
- Classes, visibility,
final, DI, early return (php-style-classes-design.md).
- Verify, PHP-CS-Fixer, Laravel Pint, or PHPCS (PSR-12) + PHPStan/Psalm on changed paths.
Red Flags
- Closing
?> in pure PHP class files
ini_set / echo in PSR-4 autoloaded class file
- Loose
== without documented intent
$name = null + ?: default instead of typed default
Singleton::getInstance() for domain services
- Public mutable properties on domain objects
- Magic numbers in conditionals
Verification
php-cs-fixer fix --dry-run / ./vendor/bin/pint --test / PHPCS PSR-12 on changed files
- PHPStan/Psalm at project level on touched namespaces
- Capsule checklist on public API review
References
awesome-guidelines/references/php-style-learning-note.md
awesome-guidelines/references/php-style-formatting-layout.md
awesome-guidelines/references/php-style-files-namespaces.md
awesome-guidelines/references/php-style-types-comparisons.md
awesome-guidelines/references/php-style-classes-design.md
1---2name: php-coding-practices3description: Use when authoring or reviewing PHP, PSR-12 layout, PSR-1/PSR-4 file hygiene, strict_types, identical comparison, typed APIs, visibility, final classes, and constructor injection over singletons.4---56# PHP Coding Practices78Application skill for PHP style learning (from the archived `awesome-guidelines` style capsules). For Laravel/Symfony/WordPress stack patterns, load stack capsules under `skills/*-foundation`.910## Core Principle1112PHP readability is **PSR mechanical layout plus strict typed APIs**, side-effect-free autoload files, identical comparison, injected dependencies.1314## When to Use / NOT1516- PHP application/library source, Composer packages, PHPCS/Pint/PHP-CS-Fixer CI.17- Reviewing namespaces, types, comparison, class design.1819**NOT when:**2021- Non-PHP code.22- Generated stubs (PHPUnit mocks, protobuf), validate generator config instead.23- CMS-specific rules (WordPress/Drupal), use stack capsules under `skills/*-foundation`.2425## Workflow26271. **Format & layout**, PSR-12 indent, braces, imports, LF endings (`php-style-formatting-layout.md`).282. **Files & namespaces**, PSR-4 side-effect-free files, PascalCase/camelCase (`php-style-files-namespaces.md`).293. **Types**, `strict_types`, hints, `===`, `??` (`php-style-types-comparisons.md`).304. **Classes**, visibility, `final`, DI, early return (`php-style-classes-design.md`).315. **Verify**, PHP-CS-Fixer, Laravel Pint, or PHPCS (PSR-12) + PHPStan/Psalm on changed paths.3233## Red Flags3435- Closing `?>` in pure PHP class files36- `ini_set` / `echo` in PSR-4 autoloaded class file37- Loose `==` without documented intent38- `$name = null` + `?:` default instead of typed default39- `Singleton::getInstance()` for domain services40- Public mutable properties on domain objects41- Magic numbers in conditionals4243## Verification4445- `php-cs-fixer fix --dry-run` / `./vendor/bin/pint --test` / PHPCS PSR-12 on changed files46- PHPStan/Psalm at project level on touched namespaces47- Capsule checklist on public API review484950## References5152- `awesome-guidelines/references/php-style-learning-note.md`53- `awesome-guidelines/references/php-style-formatting-layout.md`54- `awesome-guidelines/references/php-style-files-namespaces.md`55- `awesome-guidelines/references/php-style-types-comparisons.md`56- `awesome-guidelines/references/php-style-classes-design.md`