Skip to content
Latchkey

PHP Deprecation Notices Failing CI - Fix error_reporting

A Deprecated: notice - common after upgrading PHP, such as the PHP 8.1 dynamic-properties and implicit-nullable deprecations - is being promoted to a failure because error_reporting includes E_DEPRECATED or PHPUnit is configured to fail on deprecations.

What this error means

CI fails on lines that emit "Deprecated: Creation of dynamic property X is deprecated" or "Deprecated: ... implicitly marking parameter as nullable is deprecated", even though the code still runs. Locally it passes because deprecations are not promoted to failures.

PHP / PHPUnit output
Deprecated: Creation of dynamic property App\User::$nickname is deprecated in
/app/src/User.php on line 22

# PHPUnit
1 test triggered 1 deprecation:
1) App\Tests\UserTest::testName
Creation of dynamic property ... is deprecated

Common causes

New deprecations after a PHP upgrade

PHP 8.1 deprecated dynamic properties and certain implicit-nullable signatures. Code that was clean on 8.0 now emits deprecations on 8.1+.

Strict error handling promotes them to failures

An error_reporting = E_ALL plus a custom error handler, or PHPUnit’s failOnDeprecation, turns a notice into a non-zero exit.

How to fix it

Fix the deprecation at the source

Address dynamic properties with the #[\AllowDynamicProperties] attribute or by declaring the property; make implicit-nullable parameters explicit.

PHP
// declare the property instead of setting it dynamically
class User {
    public ?string $nickname = null;
}
// or explicit nullable type
function setName(?string $name): void {}

Scope error_reporting deliberately

If you must defer fixes, exclude E_DEPRECATED consciously rather than globally silencing errors.

Terminal
php -d error_reporting="E_ALL & ~E_DEPRECATED" bin/run.php

Tune PHPUnit deprecation handling

Decide whether PHPUnit should fail on deprecations via its configuration.

phpunit.xml
<!-- phpunit.xml -->
<phpunit failOnDeprecation="false" displayDetailsOnTestsThatTriggerDeprecations="true">

How to prevent it

  • Run a CI matrix that includes the next PHP version to surface deprecations early.
  • Use static analysis (PHPStan/Psalm) to flag deprecated usage before runtime.
  • Treat deprecations as a backlog to fix, not noise to permanently silence.

Related guides

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