php-best-practices
Skill3 starsChanged 12 days agoMITView on GitHub
Implement, refactor, debug, or review PHP with explicit runtime compatibility, precise contracts, and framework-aware validation. Use for substantive PHP engineering work; simple conceptual questions do not require this workflow.
4 other projects use a version of this.
Adopted by
Most recently taken up by
- davidanthonyn/claude-skillstheir own version, first seen Oct 20, 2026
- kazakevic/claude-skillstheir own version, first seen Oct 11, 2026
- rcdelfin/agentkittheir own version, first seen Aug 28, 2026
- mduongvandinh/ai-best-practices-skillstheir own version, first seen Feb 19, 2026
Other versions4 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 4
- mduongvandinh/ai-best-practices-skills★ 18same name
- rcdelfin/agentkit★ 2same name
- davidanthonyn/claude-skills★ 0same name
- kazakevic/claude-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository5 other files it gives its agents.
- lazarus-modeSkill
- pr-splitterSkill
- rust-best-practicesSkill
- rust-portSkill
- rust-reviewSkill
The file
We split this skill into the rules it gives an agent
6 rules. 0 are common, 6 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
6
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 16
Before refactoring, identify observable contracts: return values, exceptions, side effects, ordering, serialization, and public signatures.
- Distinctive: line 20
Prefer cohesive functions and objects with clear names and explicit dependencies.
- Distinctive: line 25
Treat final, readonly, constructor promotion, enums, and property hooks as design choices with version and compatibility costs.
- Distinctive: line 26
Keep untrusted data separate from executable commands and queries.
- Distinctive: line 27
Document contracts types cannot convey: failure modes, units, encoding, side effects, and meaningful ordering or lifecycle constraints.
- Distinctive: line 35
Test behaviour with independent expectations and relevant boundary inputs.
“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
BeautifulPHP
Produce clear, idiomatic PHP that satisfies the requested behaviour on the project's supported runtimes. Follow repository instructions and established framework conventions. Keep changes scoped; introduce dependencies and abstractions only when they solve a concrete problem.
Establish the target and contract
Read affected code, tests, Composer manifests, analysis configuration, and any existing CI, container, or deployment settings. Establish the supported PHP range, required extensions, framework version, and actual execution environment. Distinguish a library's consumer compatibility promise from an application's deployment target. A local interpreter or lockfile alone does not establish either.
Reconcile conflicting version evidence before compatibility-sensitive edits. If the target is unresolved, state the uncertainty and ask for the missing decision while continuing independent work. Do not silently raise the minimum version, narrow the supported range, or bypass platform requirements. Check syntax, built-in APIs, dependencies, and deprecations against the full promised range. Read compatibility when establishing a target, upgrading PHP, or using version-sensitive features.
Before refactoring, identify observable contracts: return values, exceptions, side effects, ordering, serialization, and public signatures. Preserve them unless the request authorises changes. Documenting a difference does not authorise it. Add focused regression coverage for demonstrated bugs and fragile boundaries.
Implement deliberately
- Prefer cohesive functions and objects with clear names and explicit dependencies. Use interfaces for real substitution or public contracts, not one per class. Avoid speculative layers, service locators, global mutable state, and unmeasured optimisation; respect established framework mechanisms.
- Express meaningful constraints with native parameter, return, and property types supported by the target. Use PHPDoc for additional information such as generics and array shapes. Validate external data before treating it as a domain value; casts and type annotations are not validation.
- Distinguish missing keys, null, false, zero, and empty strings. Choose comparisons and presence checks by semantics. Consider array-key coercion, list versus map shape, byte versus character operations, and JSON representation. Read types and contracts when these boundaries or public APIs change.
- Apply strict typing deliberately. Scalar argument strictness depends on the calling file; adding declarations or narrower types can change accepted inputs. Do not present strict typing as sanitisation or apply it mechanically during compatibility-preserving refactors.
- Use exceptions for failures according to project contracts, preserving useful context and previous causes. Distinguish normal absence from failure. Catch at a recovery or translation boundary; do not swallow Throwable, suppress diagnostics, or return a success-shaped fallback after failure. Release resources with appropriate cleanup and transactions.
- Treat final, readonly, constructor promotion, enums, and property hooks as design choices with version and compatibility costs. Check inheritance, named arguments, reflection, serialization, and framework hydration before changing exposed structures.
- Keep untrusted data separate from executable commands and queries. Enforce authorisation at the operation boundary, encode output for its destination, and bound resource use. Read security and boundaries for HTTP, persistence, filesystem, process, or external-service changes.
- Document contracts types cannot convey: failure modes, units, encoding, side effects, and meaningful ordering or lifecycle constraints. Prefer examples that exercise realistic failure handling over comments that repeat the code.
Validate and review
Run validation locally using the project's available formatter, analyser, and test commands. CI is optional; use the existing provider when present. Do not require GitHub Actions or introduce CI unless requested. Follow existing PHPStan or Psalm configuration rather than imposing a new tool or maximum level. Preserve baseline debt without hiding new diagnostics. Follow the existing style; when none exists, use a target-compatible PHP-FIG PER Coding Style configuration. Do not reformat unrelated files.
Read testing and tooling when selecting checks or changing validation configuration. Lint and run focused tests on the minimum supported PHP runtime and other relevant supported versions when available. Compatibility scanning and static analysis supplement runtime tests; they do not replace them. Verify required extensions and dependency platform requirements on the real execution environment.
Test behaviour with independent expectations and relevant boundary inputs. For bug fixes, demonstrate that the regression check fails before the fix when practical. Inspect the final diff for accidental contract changes, unsupported features, hidden warnings, and unrelated edits.
For review-only requests, report actionable findings with locations, triggers, and consequences; do not rewrite code unless asked. Distinguish demonstrated defects from preferences. For all work, report checks actually run, runtime versions, existing failures, and material verification gaps. Never claim compatibility or model effectiveness from packaging checks alone.
Sources and inspiration
Original guidance inspired by Morgan Linton's BeautifulRust approach. Compatibility, types and contracts, security and boundaries, and testing and tooling link the authoritative sources behind these summaries. Load only the references relevant to the task.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

