Skip to content
BETAGuardrails are in beta. The library, the configuration format and the CLI command can still change.

Guardrails / php

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.

Idphp/version-declared
Versionv1
Categoryphp
Default severitywarning
Interpreterpython3
Timeout30 seconds
Violations tolerated0
Collectsphp

Collectors

This guardrail gathers nothing itself. It depends on the collectors below, which the CLI runs once per build before any check, and reads what they found out of GUARDRAIL_FACTS. A collector that collects nothing skips this guardrail rather than failing it.

CollectorGathersInputs it is given
phpThe 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, passed straight through. Configuring one in buildnote.json changes what is collected, and two guardrails configured the same way share the one collection.

Configuration

json
{
  "guardrails": {
      "failOn": "error",
      "comment": true,
      "checks": [
          {
              "use": "php/version-declared@v1",
              "severity": "warning",
              "with": {
                  "projectDir": ".",
                  "minVersion": "8.1"
              },
              "exemptions": []
          }
      ]
  }
}

Inputs

InputDescriptionDefaultEnvironment variable
projectDirDirectory holding the project, relative to the directory the CLI runs in..GUARDRAIL_INPUT_PROJECTDIR
minVersionOldest PHP version accepted. A declared version below this is a violation.8.1GUARDRAIL_INPUT_MINVERSION

How to fix

Declare the runtime the package supports in composer.json:

json
{
  "require": { "php": ">=8.2" }
}

Where the deployed runtime is known, add "config": { "platform": { "php": "8.2.18" } } beside it, because that is the version Composer resolves against. Without either, composer update resolves against whichever PHP the machine running it happens to carry, so a package needing a newer runtime than production has is installed happily and the failure lands on the first request rather than at install time.

More in php

  • php/dependencies-constrained. Every package the manifest requires names a version constraint, rather than accepting whatever the registry serves.
  • php/lockfile-committed. The project commits composer.lock, so an install of the same commit resolves the same versions.

All 3 php guardrails

Buildnote Limited
Registered in England and Wales, Reg: 16140412