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 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 42Common 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
- The first line names the file and line - start there.
- For "on null", trace back where the value should have been set and handle the null case.
- 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.
php -d display_errors=1 -d error_reporting=E_ALL bin/run.phpHow 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.