PHP error guide

New PHP syntax used on an older runtime: meaning and fix

Error summary

Run the code on its declared minimum PHP version or rewrite the unsupported construct; do not hide parser errors.

What it means

Run the code on its declared minimum PHP version or rewrite the unsupported construct; do not hide parser errors.

What the error means

The older parser does not recognize syntax introduced by a newer PHP release, such as match, attributes, enums, readonly constructs, or newer type syntax.

Why PHP produces it

Source code was built or tested on a newer interpreter than the runtime parsing the deployed file.

PHP version notes

The behavior described for New PHP syntax used on an older runtime applies to PHP 7.4–8.4 unless a narrower version is stated; exact wording can vary by SAPI and patch release.

Most common causes

  • A PHP 8 construct is deployed to PHP 7.4.
  • A dependency release raised its PHP minimum.
  • Different nodes in a pool run different PHP minor versions.

Minimal examples

BAD — reproduces the problem

php
// Deploy match expressions while production still runs PHP 7.4

FIXED — safer pattern

shell
/usr/bin/php8.3 -l /srv/app/app.php

Step-by-step diagnosis

  1. Run php -l with the exact failing runtime.
  2. Identify when the unexpected token syntax was introduced.
  3. Check every serving node and scheduled binary version.

Fixes

Make source and runtime compatible

Upgrade the site-specific runtime or use syntax supported by the declared minimum.

php
$label = match ($status) {
    200 => "ok",
    default => "other",
};

Common mistakes when fixing it

  • Blaming OPcache before checking the parser version.
  • Editing vendor files in production.
  • Suppressing deployment lint checks.

How to prevent it

  • Lint with the oldest supported PHP version in CI.
  • Declare dependency platform constraints.
  • Keep runtime versions consistent across nodes.

Web server / environment notes

fpm, apache, cli. Parsing fails before application error handlers can run.

Tags: fpm,apache,cli

Categories