php-code-conventions
/php-code-conventions
ACTIVATE whenever writing or modifying PHP code in src/, creating controllers, services, repositories, specifications, or any production PHP class. ACTIVATE for code review, formatting questions, or 'coding standards'. Provides PHP-specific code style examples for the cross-language rules defined in craft:code-style-principles, plus PHP-specific rules (no empty(), nullsafe operator access, nowdoc, constructor parameter ordering with promoted properties). DO NOT use for: test code conventions (see phpunit:php-test-conventions), SQL formatting (see php-sql-conventions).
- Author
- fabiensalles ↗
- Repository
- claude-marketplace ↗
- Licence
- MIT
- Last repository change
- 12.10.2026
Assessment and security
- Files in this package
- 2
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 1
No signals detected. Repository changed on 12.10.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
ACTIVATE whenever writing or modifying PHP code in src/, creating controllers, services, repositories, specifications, or any production PHP class. ACTIVATE for code review, formatting questions, or 'coding standards'. Provides PHP-specific code style examples for the cross-language rules defined in craft:code-style-principles, plus PHP-specific rules (no empty(), nullsafe operator access, nowdoc, constructor parameter ordering with promoted properties). DO NOT use for: test code conventions (see phpunit:php-test-conventions), SQL formatting (see php-sql-conventions).
Triggers from the description
Original author description
ACTIVATE whenever writing or modifying PHP code in src/, creating controllers, services, repositories, specifications, or any production PHP class. ACTIVATE for code review, formatting questions, or 'coding standards'. Provides PHP-specific code style examples for the cross-language rules defined in craft:code-style-principles, plus PHP-specific rules (no empty(), nullsafe operator access, nowdoc, constructor parameter ordering with promoted properties). DO NOT use for: test code conventions (see phpunit:php-test-conventions), SQL formatting (see php-sql-conventions).
How it works
- PHP-specific: Nullsafe Operator ?->
- PHP-specific: NEVER Use empty()
- PHP-specific: Constructor Parameter Ordering
- PHP-specific: Heredoc / Nowdoc (PER Section 10)
- Quick Reference (PHP-specific only)
SKILL.md preview
--- name: php-code-conventions description: "ACTIVATE whenever writing or modifying PHP code in src/, creating controllers, services, repositories, specifications, or any production PHP class. ACTIVATE for code review, formatting questions, or 'coding standards'. Provides PHP-specific code style examples for the cross-language rules defined in craft:code-style-principles, plus PHP-specific rules (no empty(), nullsafe operator access, nowdoc, constructor parameter ordering with promoted properties). DO NOT use for: test code conventions (see phpunit:php-test-conventions), SQL formatting (see php-sql-conventions)." --- # Code Conventions — PHP > 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's `references/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`. ## PHP-specific: Nullsafe Operator `?->` Use `?->` to avoid nested null checks. When using `match` with nullable input, add `null` as a case. ## PHP-specific: NEVER Use `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)` | ## PHP-specific: Constructor Parameter Ordering Mandatory parameters before optional; within each group, **promoted properties before simple parameters**: 1. Promoted mandatory (`public`/`private`/`protected`, required) 2. Simple mandatory (non-promoted, required) 3. Promoted optional (nullable promoted property) 4. Simple optional (nullable simple parameter) > See `references/code-examples.md` for correct and incorrect examples. ## PHP-specific: Heredoc / Nowdoc (PER Section 10) Reference: [PER Coding Style — Section 10](https://www.php-fig.org/per/coding-style/#10-heredoc-and-nowdoc) **A nowdoc SHOULD be used wherever possible.** Heredoc MAY be used only when nowdoc does not satisfy requirements. Indentation: 1. Declaration begins on the **same line** as its context. 2. Content is indented **once past the scope indentation**. 3. Closing identifier is at the **same indentation level as the content**. > See `references/code-examples.md` for PER-compliant and non-compliant examples. ## Quick Reference (PHP-specific only) > 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 |
Files in this package (2)
- SKILL.md 3 KB
- references/code-examples.md 7 KB
Versions
The database has no other skills named php-code-conventions.
Database snapshot: 13.11.2026 · package version a01ce1e32b25 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100code-style-principles
ACTIVATE whenever writing or modifying production code in src/, in any language — this is the base layer these rules build on. ACTIVATE for code review, formatting questions, or 'coding standards'. Covers cross-language code style: control-structure spacing, early-return… - 100php-sql-conventions
ACTIVATE when writing SQL queries in PHP code, using Doctrine DBAL, or formatting database queries. ACTIVATE for 'SQL', 'query', 'DBAL', 'JOIN', 'SELECT'. Covers: query direction convention (start from known entity), nowdoc formatting for SQL, column listing, JOIN ordering. DO… - 100php
PHP language conventions, modern idioms, and type system. Invoke whenever task involves any interaction with PHP code — writing, reviewing, refactoring, debugging, or understanding PHP projects. - 100php-coding-standards
Invoke BEFORE writing or modifying any PHP code. Provides coding standards and naming conventions for Nette repos: TABs, single quotes, strict_types, PER Coding Style modifications, use statement ordering. Use this whenever creating, modifying, or refactoring any PHP code - even… - 87php-conventions
Modern PHP idioms for any PHP project (PHP 8.1+): readonly properties, enums, match expressions, constructor property promotion, typed properties, named arguments, nullsafe operator, first-class callable syntax, strict_types, PSR-12 style, and null discipline. Apply when the… - 100php-guide
PHP language guardrails, patterns, and best practices for AI-assisted development. Use when working with PHP files (.php), composer.json, or when the user mentions PHP. Provides type declaration patterns, Composer conventions, PSR standards, and testing guidelines specific to…