composer and ecosystem

Composer Platform PHP Constraints

The PHP constraint in composer.json tells Composer which runtime versions the project supports. Accurate platform constraints prevent packages being installed on runtimes that cannot execute them.

Working Knowledge

  • Declare an explicit supported PHP range in require.php.
  • Match constraints to deployed PHP versions, not only a developer laptop.
  • Use Composer platform configuration deliberately when resolving for another environment.
  • Check required PHP extensions such as ext-json or ext-pdo when the application depends on them.
  • Test supported runtimes in CI when a library promises a range.

Declare Runtime Requirements

{
  "require": {
    "php": "^8.3",
    "ext-json": "*",
    "ext-pdo": "*",
    "ext-mbstring": "*"
  }
}

The package now tells Composer which PHP versions and extensions the application expects. This catches missing runtime capabilities before a request fails in production.

Check The Current Machine

composer check-platform-reqs

Run this in the environment that matters: the application container, CI image, server, or worker runtime.

Platform Overrides Need Care

Composer can resolve dependencies as if it were running on another PHP version:

{
  "config": {
    "platform": {
      "php": "8.3.0"
    }
  }
}

This is useful when a developer laptop runs newer PHP than production. It does not install that runtime or prove the code works there. CI still needs to test the supported versions.

In Application Work

A deployment can fail even when local installation succeeds if local PHP is newer. Keep runtime inventory and Composer constraints aligned.

What To Check

Before moving on, make sure you can declare PHP and extension requirements, run platform checks in the real runtime, and explain what a platform override does and does not prove.

Practice

Practice: Review Runtime Constraints

Add PHP and extension constraints to a sample manifest, then compare them with the local runtime using Composer platform checks.

Requirements

  • State supported PHP versions.
  • List required extensions.
  • Compare local, CI, and production runtimes.
  • Explain any platform override.
Show solution

Use composer check-platform-reqs in the target environment. If Composer's config.platform is set, remember that it affects dependency resolution but does not install or upgrade the real runtime.