← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

Cross-Version Compatibility Testing

PHP PHP 7.0+ Intermediate
debt(d5/e3/b3/t6)
d5 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches' (d5), PHPCompatibility PHPCS sniffs and CI matrix testing catch version-incompatible API usage, but require explicit setup — silent without them.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3), quick_fix involves adding composer.json constraint, PHPCS rule, and CI matrix config — multiple small config changes but no code refactor.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3), the CI matrix and sniff config impose ongoing maintenance overhead (adding new PHP versions, dropping old ones) but stays contained to CI/tooling layer.

t6 Trap Cognitive debt — how counter-intuitive correct behaviour is

Between 'notable trap' (t5) and 'serious trap' (t7), landing at t6 — the misconception that composer.json's php constraint actually verifies compatibility (it only documents intent) is a common and misleading gotcha.

About DEBT scoring →

TL;DR

Testing PHP code across multiple versions uses CI matrix builds, phpenv/phpbrew, Docker multi-version setups, and static analysis to catch compatibility issues before deployment.

Explanation

Strategies: (1) GitHub Actions matrix: [php: ['8.1','8.2','8.3']] runs tests against each version. (2) PHPStan with phpCompatibilityFixer to detect usage of features not available in minimum PHP version. (3) composer check-platform-reqs validates extension requirements. (4) phpenv or phpbrew to switch PHP versions locally. (5) Docker: test against official php:8.x-cli images. (6) PHPCompatibility (PHPCS sniff): checks code against target PHP version. Key: declare minimum PHP version in composer.json require->php field and enforce with tooling.

Common Misconception

Setting the PHP version requirement in composer.json is sufficient — it documents but doesn't verify compatibility. Use PHPCompatibility sniffs to actually check.

Why It Matters

Library authors and teams upgrading PHP need to verify compatibility across versions — CI matrix testing catches regressions before they affect users.

Common Mistakes

  • Only testing against one PHP version in CI.
  • Not specifying minimum PHP version in composer.json.
  • Not using PHPCompatibility PHPCS sniffs to catch API usage differences.

Code Examples

✗ Vulnerable
# composer.json — no PHP version constraint:
{
    "require": {
        "php": "*"
    }
}
✓ Fixed
# composer.json:
{
    "require": {
        "php": ">=8.1"
    }
}

# GitHub Actions:
matrix:
  php: ['8.1', '8.2', '8.3']

# phpcs.xml:
<rule ref="PHPCompatibility"/>
<config name="testVersion" value="8.1-"/>

Added 23 Mar 2026
Views 39
Rate this term
No ratings yet
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Medium
⚡ Quick Fix
Add PHP version constraint to composer.json. Add PHPCompatibility PHPCS rule. Set up CI matrix for supported PHP versions. Run phpcs --standard=PHPCompatibility.
📦 Applies To
PHP 7.0+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
PHPCompatibility|testVersion
Auto-detectable: ✓ Yes phpcs phpstan ci
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: Medium Context: File


✓ schema.org compliant