/php:php-code-conventionsfrom php
PHP code style conventions extending PSR-12/PER: nullsafe operator usage, forbidding empty(), constructor parameter ordering with promoted properties, heredoc/nowdoc rules.
Ships in php. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
The cross-language rules (control-structure spacing, early return, continue vs if/else, parameter ordering, explicit checks, flatten null checks) are defined in
craft:code-style-principles. This skill keeps PHP-specific syntax, PSR-12/PER extensions, and pointers to the project'sreferences/code-examples.md.
All code complies with PSR-12 and PER Coding Style. The rules below are project-specific PHP conventions that go beyond these standards.
For complete worked examples (control-structure spacing, early return, continue patterns, parameter ordering, heredoc/nowdoc), read
references/code-examples.md.
?->Use ?-> to avoid nested null checks.
When using match with nullable input, add null as a case.
empty()The empty() function has unpredictable behavior with different types and hides potential bugs.
| Type | Correct | Avoid |
|---|---|---|
| Arrays | $array === [] | empty($array) |
| Strings | $string === '' | empty($string) |
| Null | $value === null | empty($value) |
Mandatory parameters before optional; within each group, promoted properties before simple parameters:
public/private/protected, required)See
references/code-examples.mdfor correct and incorrect examples.
Reference: PER Coding Style — Section 10
A nowdoc SHOULD be used wherever possible. Heredoc MAY be used only when nowdoc does not satisfy requirements.
Indentation:
See
references/code-examples.mdfor PER-compliant and non-compliant examples.
For the cross-language quick reference (early return, continue, blank lines, parameter ordering), see
craft:code-style-principles.
| Rule | Example |
|---|---|
| Nullsafe for nested null checks | $a?->b?->c instead of nested if |
No empty() function | $array === [] instead of empty($array) |
| Prefer nowdoc | <<<'SQL' instead of <<<SQL |
| Heredoc/nowdoc indentation | Content +1 level, closing same as content |
| Constructor params | Promoted-mandatory → simple-mandatory → promoted-optional → simple-optional |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
10 skills in this plugin
/php-8-0ACTIVATE when calling a constructor, method or function with four or more arguments in a PHP 8.0+ project — value objects, contract requests, factories, projections, test fixtures. Covers: mandatory named arguments from the fourth argument on. DO NOT use for: calls of three arguments or fewer, PHP 8.1 features (see php-8-1), PHP 8.2 features (see php-8-2), PHP 8.3 features (see php-8-3)./php-8-1ACTIVATE when passing a method as a callback in a PHP 8.1+ project — event listeners, validator callbacks, Twig functions, array_map/usort callables. Covers: mandatory first-class callable syntax (`$this` method reference with `(...)`) over array/string callables. DO NOT use for: general PHP syntax, PHP 8.2 features (see php-8-2), PHP 8.3 features (see php-8-3)./php-Other plugins' skills for the same job
npx claudepluginhub fabiensalles/claude-marketplace --plugin php