Skip to content
Latchkey

PHP "Fatal error: Uncaught Error" in CI - Diagnose Runtime Failures

An Error (or one of its subclasses like TypeError) was thrown and never caught, so PHP terminated the script. In CLI/CI this exits non-zero (commonly 255), failing the step.

What this error means

A script or command aborts with "PHP Fatal error: Uncaught Error: ..." and a stack trace, and the CI step fails. It is genuine application logic - calling a method on null, a type mismatch, or an undefined class.

PHP error
PHP Fatal error:  Uncaught Error: Call to a member function format() on null in
/app/src/Report.php:42
Stack trace:
#0 /app/bin/run.php(11): App\Report->render()
#1 {main}
  thrown in /app/src/Report.php on line 42

Common causes

Calling a method on null or a wrong type

Call to a member function X() on null means a value you expected to be an object was null. A TypeError means an argument or return type did not match the declared type.

A missing or misnamed class

Class "X" not found thrown as an Error usually points at an autoload or namespace problem rather than transient infra.

How to fix it

Read the trace and guard the null/type

  1. The first line names the file and line - start there.
  2. For "on null", trace back where the value should have been set and handle the null case.
  3. For a TypeError, align the argument/return types or the value passed.

Surface full errors in CI

Make sure CI shows errors and stack traces so failures are diagnosable.

Terminal
php -d display_errors=1 -d error_reporting=E_ALL bin/run.php

How to prevent it

  • Use static analysis (PHPStan, Psalm) in CI to catch null and type errors before runtime.
  • Enable strict types and declare parameter/return types.
  • Add tests that exercise the failing code path.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →