PHP error guide

Required parameter follows optional parameter: meaning and fix

Error summary

Move $value before $format and update call sites by name where appropriate. The declaration places a mandatory argument after one with a default.

What it means

Move $value before $format and update call sites by name where appropriate. The declaration places a mandatory argument after one with a default.

What the error means

This message means that the declaration places a mandatory argument after one with a default. The exact signature distinguishes required parameter follows optional parameter from a generic application failure.

Why PHP produces it

The engine or service reports “Required parameter follows optional parameter” because its required precondition was not met. Move $value before $format and update call sites by name where appropriate.

PHP version notes

The required parameter follows optional parameter wording here is based on PHP 8.0+; punctuation and exception class names can differ on older branches or vendor builds.

Most common causes

  • The immediate input or configuration reaches the specific condition: the declaration places a mandatory argument after one with a default
  • The code path assumes the prerequisite for required parameter follows optional parameter has already been satisfied.
  • For required parameter follows optional parameter, development and production differ in version, extension, permissions, paths, or service configuration.
  • An earlier operation returned an unchecked value that is consumed by the line reporting required parameter follows optional parameter.

Minimal examples

BAD — reproduces the problem

php
function export($format = "csv", $value) {}

FIXED — safer pattern

php
function export($value, $format = "csv") {}

Step-by-step diagnosis

  1. Copy the complete “Deprecated: Required parameter $value follows optional parameter $format” text and retain the first application stack frame.
  2. Reproduce required parameter follows optional parameter in the same SAPI and environment listed for this page.
  3. Before changing required parameter follows optional parameter, inspect the preceding value or directive and verify its type, path, version, and permissions.
  4. Apply the narrow correction—move $value before $format and update call sites by name where appropriate—then repeat the original request once.

Fixes

Correct the failing prerequisite

Move $value before $format and update call sites by name where appropriate

php
function export($value, $format = "csv") {}

Fail explicitly at the boundary

Validate the condition before the operation that emits required parameter follows optional parameter, and log a safe diagnostic without credentials or full production paths.

Common mistakes when fixing it

  • Suppressing required parameter follows optional parameter instead of correcting its upstream condition.
  • Testing required parameter follows optional parameter only with the CLI binary when the failing request runs under FPM or Apache.
  • Changing a global setting for required parameter follows optional parameter before confirming the site-specific effective configuration.

How to prevent it

  • Add a focused test that exercises the boundary responsible for required parameter follows optional parameter.
  • Keep runtime versions, extensions, configuration, and deploy artifacts affecting required parameter follows optional parameter reproducible.
  • Validate external data and service return values before they can trigger required parameter follows optional parameter.

Web server / environment notes

cli, fpm, composer. The failure occurs where the declaration places a mandatory argument after one with a default

Tags: cli,fpm,composer

Categories