wimg/php-compatibility
PHP_CodeSniffer ruleset that checks your code for compatibility with different PHP versions, helping you spot syntax and features that would break when upgrading or downgrading PHP.
Architecture fit. PHPCompatibility is not an application library — it is a ruleset (a collection of sniffs) consumed by PHP_CodeSniffer. Architecturally it is a build-time / CI-time static analysis tool, not a runtime dependency. That makes its fit essentially universal for any PHP codebase, and it slots cleanly alongside PHPStan/Psalm (type and semantic analysis) and Rector (automated remediation). For a TPM, the relevant framing is not "does this integrate with our service architecture" but "does it fit our delivery pipeline and toolchain governance." The answer is yes, with two caveats: (1) it must be paired with a PHP_CodeSniffer version capable of tokenizing the newest PHP syntax you actually use, and (2) it is detection-only — it produces findings, not fixes.
Integration feasibility. Low friction. It installs as a dev-only Composer dependency, registers via PHPCS's installed_paths, and runs against a phpcs.xml.dist with a testVersion range (e.g. 8.1-8.4). A single engineer can stand up a proof-of-concept in under a day against a representative module. The main configuration surface is small and well-documented: target version range, sniff exclusions, file scope, and severity. Ecosystem extensions reduce false positives meaningfully — PHPCompatibilityWP for WordPress, and the Paragonie compat standards to suppress noise from polyfills already in use.
Technical risk. Moderate, and mostly manageable:
PHPCompatibility/PHPCompatibility but the package in this brief is referenced as wimg/php-compatibility, the legacy abandoned name. The maintained Packagist package is phpcompatibility/php-compatibility. Any dependency manifest referencing the old name is a red flag to resolve before rollout.installed_paths is misconfigured or testVersion is unset, the run completes successfully with zero findings. A green pipeline then means nothing. This failure mode must be actively guarded against with a known-violation smoke test.eval, string callbacks, generated code, or runtime extension availability. It is a strong filter, not a proof of compatibility.Key questions. What is our target PHP version and timeline? Which PHPCS major version is our platform standardized on? Is any code shipped to customers in a way that touches LGPL obligations? Do we have a policy for suppressing false positives (inline ignores with justification vs. ruleset exclusions)? Is Rector already in the toolchain to close the loop from detection to remediation?
Stack fit. Drop-in for any Composer-based PHP project, including monorepos and legacy applications. It is orthogonal to frameworks — Laravel, Symfony, WordPress, and custom stacks all work, with WordPress benefiting from the WP-specific standard. It belongs in the same CI tier as linting and static analysis: fast, deterministic, no infrastructure, no external services.
Migration path. Treat this as a version-readiness program, not a tooling install. Sequence:
8.1-8.4) in report-only mode; triage findings into blocking, deferred, and false-positive buckets.testVersion as a blocking gate, and add a second gate once the old version is retired.This ordering matters: turning on blocking mode before triage will stall delivery on a backlog of pre-existing findings.
Compatibility considerations. Pin PHP_CodeSniffer and PHPCompatibility together and upgrade them as a pair. Verify the tokenizer handles your newest syntax — older PHPCS versions fail to parse newer language constructs, which manifests as parse errors or missed findings rather than clean output. If the codebase also uses other PHPCS standards, confirm installed_paths includes all of them; PHPCS resolves standards globally and a partial setting silently drops rulesets.
Sequencing across teams. Roll out in three waves: platform team owns the shared ruleset and CI job; one pilot application validates signal-to-noise; then broad enablement with report-only mode defaulting to on and blocking mode opt-in per repository. Provide a shared phpcs.xml.dist template so teams inherit a consistent testVersion rather than each inventing one.
Maintenance. Low-to-moderate, and mostly external. The project is actively maintained — the late-2025 release cadence indicates it tracks current PHP versions promptly. The real maintenance load is internal: a named owner must update the PHPCS/PHPCompatibility pair on a deliberate cadence (quarterly, or when a new PHP minor lands), re-baseline findings, and manage the exclusion list. Unmanaged, the exclusion list becomes the de facto policy and the gate degrades into theater.
Support. Developer-facing support burden is low — findings are self-describing ("function removed in PHP 8.0"). The support burden concentrates in triage: distinguishing genuine incompatibilities from polyfilled functions, framework-provided shims, and conditional code paths. Budget for a documented suppression protocol (inline ignore with a linked ticket, reviewed at code review) so exclusions are auditable rather than silent.
Scaling. PHPCS is CPU-bound and single-process per file, so large codebases need --parallel, result caching, and diff-scoped scanning in pull requests with full scans on a nightly or release-candidate cadence. Runtime is linear in files scanned; for very large legacy trees, scoping to changed files is the pragmatic default. Memory is generally fine, but pathological generated files can exhaust limits and should be excluded by path.
Failure modes to plan for:
testVersion yields a clean run with no analysis. Mitigate with a fixture containing a known violation asserted in CI.Ramp-up. Developer ramp-up is minimal — findings are readable and actionable, and no new language or mental model is required. Platform-team ramp-up is moderate: roughly one to two weeks to design the ruleset, wire CI, establish the suppression protocol, and produce the first triage report. The organizational ramp-up — getting teams to treat the gate as a release blocker rather than advisory noise — is the longest pole and should be driven explicitly by the TPM with a clear enforcement date and an amnesty window for pre-existing findings.
How can I help you explore Laravel packages today?