PHP version is declared
php/version-declared@v1
The project declares the PHP version Composer resolves against, and that version is no older than the configured floor.
| Id | php/version-declared |
| Version | v1 |
| Category | php |
| Default severity | warning |
| Interpreter | python3 |
| Timeout | 30 seconds |
| Violations tolerated | 0 |
| Collects | php |
Collectors
This guardrail doesn't gather anything itself. It relies on the collectors below, which the CLI runs once per build before any check, and reads what they found from GUARDRAIL_FACTS. If a collector collects nothing, this guardrail is skipped, not failed.
| Collector | Gathers | Inputs it is given |
|---|---|---|
php | The Composer project in the project directory: the package it declares, the PHP version and extensions it asks for, the packages it requires and which of them are pinned, and whether the lock file is committed. | projectDir |
The inputs above are this guardrail's own inputs, passed straight through to the collector. Setting one in buildnote.json changes what is collected, and two guardrails configured the same way share a single collection.
Configuration
{
"guardrails": {
"failOn": "error",
"checks": [
{
"use": "php/version-declared@v1",
"severity": "warning",
"with": {
"projectDir": ".",
"minVersion": "8.1"
},
"exemptions": []
}
]
}
}Inputs
| Input | Description | Default | Environment variable |
|---|---|---|---|
projectDir | Directory holding the project, relative to the directory the CLI runs in. | . | GUARDRAIL_INPUT_PROJECTDIR |
minVersion | Oldest PHP version accepted. A declared version below this is a violation. | 8.1 | GUARDRAIL_INPUT_MINVERSION |
How to fix
Declare the PHP versions the package supports in composer.json:
{
"require": { "php": ">=8.2" }
}If you know the deployed runtime, add "config": { "platform": { "php": "8.2.18" } } next to it, because that is the version Composer resolves against. Without either, composer update resolves against whichever PHP the machine running it has. A package that needs a newer runtime than production installs without complaint, and the failure shows up on the first request instead of at install time.
More in php
php/dependencies-constrained. Every package the manifest requires has a version constraint, instead of accepting whatever the registry serves.php/lockfile-committed. The project commitscomposer.lock, so an install of the same commit resolves the same versions.