Creation of Dynamic Property is Deprecated

Deprecated: Creation of dynamic property App\Entity\User::$fullName is deprecated

Quick Answer

PHP 8.2 deprecated setting undeclared properties on objects. Declare the property in the class definition or use the #[AllowDynamicProperties] attribute.

Why This Happens

Starting in PHP 8.2, creating properties that are not declared in the class definition triggers a deprecation notice. This will become an error in PHP 9.0. Dynamic properties were a source of subtle bugs because typos in property names would silently create new properties instead of failing.

The Problem

class User {
    public string $name;
}
$user = new User();
$user->name = 'Alice';
$user->fullName = 'Alice Smith'; // Dynamic property deprecated

The Fix

class User {
    public string $name;
    public string $fullName;
}
$user = new User();
$user->name = 'Alice';
$user->fullName = 'Alice Smith';

Step-by-Step Fix

  1. 1

    Find the dynamic property

    Check the warning to see which property is being dynamically created and on which class.

  2. 2

    Declare the property

    Add a typed property declaration to the class for the property that was being set dynamically.

  3. 3

    Use AllowDynamicProperties if needed

    If the class intentionally uses dynamic properties, add the #[AllowDynamicProperties] attribute. But prefer declaring properties explicitly.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free