The warning is telling you that there is a property you are trying to set which isn't declared in the class or any of its parents.

When you run this:

class database {

    public $username = "root";
    public $password = "pasword";
    public $port = 3306;

    public function __construct($params = array())
    {
        foreach ($params as value)
        {
            $this->{$key} = $value;
        }
    }
}

$db = new database(array(
    'database' => 'db_name',
    'server' => 'database.internal',
));

It is roughly equivalent to this:

class database {

    public $username = "root";
    public $password = "pasword";
    public $port = 3306;
}

$db = new database;
$db->database = 'db_name';
$db->server = 'database.internal';

The warning is that there is no line in the class definition saying that $db->database or $db->server exist.

For now, they will be dynamically created as untyped public properties, but in future, you will need to declare them explicitly:

class database {
    public $database;
    public $server;
    public $username = "root";
    public $password = "pasword";
    public $port = 3306;

    public function __construct($params = array())
    {
        foreach ($params as value)
        {
            $this->{$key} = $value;
        }
    }
}

$db = new database(array(
    'database' => 'db_name',
    'server' => 'database.internal',
));

In some rare situations, you actually want to say "the properties of this class are whatever I decide to add at run-time"; in that case, you can use the #[AllowDynamicProperties] attribute, like this:

#[\AllowDynamicProperties]
class objectWithWhateverPropertiesIWant {
    public function __construct($params = array())
    {
        foreach ($params as value)
        {
            $this->{$key} = $value;
        }
    }
}
Answer from IMSoP on Stack Overflow
Top answer
1 of 9
73

The warning is telling you that there is a property you are trying to set which isn't declared in the class or any of its parents.

When you run this:

class database {

    public $username = "root";
    public $password = "pasword";
    public $port = 3306;

    public function __construct($params = array())
    {
        foreach ($params as value)
        {
            $this->{$key} = $value;
        }
    }
}

$db = new database(array(
    'database' => 'db_name',
    'server' => 'database.internal',
));

It is roughly equivalent to this:

class database {

    public $username = "root";
    public $password = "pasword";
    public $port = 3306;
}

$db = new database;
$db->database = 'db_name';
$db->server = 'database.internal';

The warning is that there is no line in the class definition saying that $db->database or $db->server exist.

For now, they will be dynamically created as untyped public properties, but in future, you will need to declare them explicitly:

class database {
    public $database;
    public $server;
    public $username = "root";
    public $password = "pasword";
    public $port = 3306;

    public function __construct($params = array())
    {
        foreach ($params as value)
        {
            $this->{$key} = $value;
        }
    }
}

$db = new database(array(
    'database' => 'db_name',
    'server' => 'database.internal',
));

In some rare situations, you actually want to say "the properties of this class are whatever I decide to add at run-time"; in that case, you can use the #[AllowDynamicProperties] attribute, like this:

#[\AllowDynamicProperties]
class objectWithWhateverPropertiesIWant {
    public function __construct($params = array())
    {
        foreach ($params as value)
        {
            $this->{$key} = $value;
        }
    }
}
2 of 9
28

Adding AllowDynamicProperties just above the class will make the warnings go away:

#[\AllowDynamicProperties]
class database {
🌐
PHP.Watch
php.watch › versions › 8.2 › dynamic-properties-deprecated
Dynamic Properties are deprecated - PHP 8.2 • PHP.Watch
PHP 8.2 introduces a new attribute in the global namespace named #[AllowDynamicProperties]. Classes declared with this attribute signals PHP to not emit any deprecation notices when setting dynamic properties on objects of that class.
Discussions

Honest Question: Why did PHP remove dynamic properties in 8.x?
For changes like this it's usually helpful to read the RFC made for the change. There will always be an rfc for large changes: https://wiki.php.net/rfc/deprecate_dynamic_properties It lays out the motivation, the consequences, and the analysis for why the backwards compatibility break was deemed OK. There is also information about how you can patch code to make it OK again, but third party libraries might make that difficult. More on reddit.com
🌐 r/PHP
44
0
May 16, 2024
Creation of dynamic property is deprecated !
Description The following code ( This should never happen when I'm using magic methods, but unfortunately it does happen sometimes ): 1); public function &__get(string... More on github.com
🌐 github.com
19
November 16, 2023
[Resolved] PHP: Creation of dynamic property is deprecated
I have several issues on the backend; e.g. not able to save an edited page where toolset blocks are used. I get error messages in the WP debug log More on toolset.com
🌐 toolset.com
September 22, 2024
Creation of dynamic property deprecated
The best solution if possible is to stop using dynamic properties and instead define them on the class - it can help prevent bugs, and has performance/memory benefits too. However; if that is not possible because dynamic properties are too embedded in your architecture, you can reenable dynamic properties on a class with the AllowDynamicProperties attribute: https://www.php.net/manual/en/class.allowdynamicproperties.php More on reddit.com
🌐 r/PHPhelp
4
1
February 3, 2023
🌐
PHP
php.net › manual › en › migration82.deprecated.php
PHP: Deprecated Features - Manual
A dynamic properties deprecation warning can be addressed by: Declaring the property (preferred). Adding the #[\AllowDynamicProperties] attribute to the class (which also applies to all child classes).
🌐
Reddit
reddit.com › r/php › honest question: why did php remove dynamic properties in 8.x?
r/PHP on Reddit: Honest Question: Why did PHP remove dynamic properties in 8.x?
May 16, 2024 -

I understand PHP has had many criticisms in the past but I'm not sure the existence of dynamic properties of instantiated objects was ever one of them. In fact, dynamic properties are pretty much the hallmark of most interpreted or dynamic programming languages. Python allows it all the time and so do many others like Ruby, Perl, etc.

I don't know what PHP developers achieved by removing dynamic properties feature from the language but one thing that resulted out of this is that many applications based on widely used veteran PHP frameworks (such as CodeIgniter and CakePHP) came to a halt all of a sudden due to an error like this after upgrading to PHP 8:

A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_URI::$config is deprecated
Filename: core/URI.php
Line Number: 102
Backtrace:
File: C:\xampp\htdocs\inv_perpus\index.php Line: 288 Function: require_once

The influence of Corporate IT in various open source foundations is pretty well known and also well known is the extent to which corporate greed goes to achieve its interests and objectives across the world. The only way to assuage this uncomfortable thought (at least in this particular case) is to ask if there was any technical merit at all in removing dynamic properties feature from a dynamic programming language?

I for one couldn't find any such merit here.

🌐
GitHub
github.com › php › php-src › issues › 12694
Creation of dynamic property is deprecated ! · Issue #12694 · php/php-src
November 16, 2023 - <?php final class Content { protected array $data = array('sequence'=>1); public function &__get(string $property) : mixed { if(isset($this->data[$property]) === false): $this->data[$property] = null; endif; return $this->data[$property]; } public function __set(string $name,mixed $value) : void { $this->data[$name] = $value; } } $content = new Content(); $result = $content->sequence * 2 + 1; $content->sequence += 1; print $result;
Author   Tak-Pesar
🌐
Toolset
toolset.com › home › toolset professional support › php: creation of dynamic property is deprecated
[Resolved] PHP: Creation of dynamic property is deprecated
September 22, 2024 - [21-Sep-2024 12:48:37 UTC] PHP Deprecated: Creation of dynamic property WP_Block_Parser::$empty_attrs is deprecated in /www/htdocs/w01c0fe8/erpscout.de/wp-content/plugins/toolset-blocks/backend/Services/ViewParsingService.php on line 335
🌐
Medium
medium.com › codetodeploy › php-deprecated-dynamic-properties-when-php-breaks-your-code-a58b80074646
PHP Deprecated Dynamic Properties: When PHP Breaks Your Code! | by Roman Huliak | CodeToDeploy | Medium
June 16, 2025 - For years, PHP developers have been freely adding properties to objects whenever they needed them: class User { public $name; public $email; } $user = new User(); $user->name = "John Doe"; $user->email = "john@example.com"; $user->isActive = true; ...
Find elsewhere
🌐
Stitcher
stitcher.io › blog › deprecated-dynamic-properties-in-php-82
Deprecated dynamic properties in PHP 8.2 | Stitcher.io
August 8, 2022 - If you really want to use dynamic properties without implementing __get and __set, there is a much better alternative than to extend from stdClass. The PHP core team has provided a built-in attribute called AllowDynamicProperties. As its name suggests, it allows dynamic properties on classes, without having to rely on sketchy extends:
🌐
Drupal
drupal.org › project › facets › issues › 3482015
In PHP 8.2+, the creation of dynamic properties is deprecated [#3482015] | Drupal.org
October 30, 2025 - Observe the deprecation warning in the log or on the page. To resolve the issue and prevent the use of dynamic properties, the termWeight property should be explicitly declared in the Result class and ResultInterface.
🌐
PHP
wiki.php.net › rfc › deprecate_dynamic_properties
PHP: rfc:deprecate_dynamic_properties
August 23, 2021 - The Locked classes RFC took an alternative approach to this problem space: Rather than deprecating/removing dynamic properties and providing an opt-in for specific classes, it instead allowed marking specific classes as locked in order to forbid creation of dynamic properties on them.
🌐
Drupal
drupal.org › project › drupal › issues › 3368250
Deprecated creation of dynamic property in TypedData [#3368250] | Drupal.org
February 12, 2025 - If you fix them you have to remove the exceptions from the baseline file. ... I'm seeing this in Drupal 10.1.8 and PHP 8.2.13, running tests on my project, thanks to symfony/phpunit-bridge. 5x: Creation of dynamic property Drupal\Core\TypedData\TypedData@anonymous::$value is deprecated 5x in ...
🌐
Drupal
drupal.org › project › twig_extender › issues › 3407742
Fix PHP 8.2 Deprecated Issue with function: Creation of dynamic property [#3407742] | Drupal.org
April 28, 2025 - Deprecated function: Creation of dynamic property Drupal\twig_extender\TwigExtenderService::$pluginManager is deprecated in Drupal\twig_extender\TwigExtenderService->__construct() (line 30 of modules/contrib/twig_extender/src/TwigExtenderService.php).
🌐
GitHub
github.com › ThemeFuse › Unyson › issues › 4324
Deprecated: Creation of dynamic property is deprecated in php8+ · Issue #4324 · ThemeFuse/Unyson
August 25, 2023 - Deprecated: Creation of dynamic .../class-breadcrumbs-builder.php on line 8 · Can be fixed by adding #[\AllowDynamicProperties] attribute above a class declaration....
Author   mwtemplates
🌐
Drupal
drupal.org › project › salesforce › issues › 3415242
Creation of dynamic property is deprecated [#3415242] | Drupal.org
January 18, 2024 - Deprecated: Creation of dynamic ...eldPluginBase.php on line 143 · I think for the RestResponseDescribe class we could fix that by adding the #[AllowDynamicProperties] attribute....
🌐
Buka Knowledge
knowledge.buka.sh › when-php-8-4-says-deprecated-creation-of-dynamic-property-what-it-means-and-how-to-fix-it
When PHP 8.4 Says “Deprecated: Creation of Dynamic Property” — What It Means and How to Fix It
November 15, 2025 - This is called a dynamic property — a property created at runtime that doesn’t exist in the class definition. It was convenient for quick prototypes, but in large codebases, it often led to typos, hard-to-track bugs, and unexpected behavior. PHP’s internal engine also had to handle these ad-hoc properties dynamically, which introduced performance overhead. Starting in PHP 8.2, dynamic property creation was marked deprecated.
🌐
Drupal
drupal.org › project › entity_language_fallback › issues › 3533985
Deprecated function: Creation of dynamic property [#3533985] | Drupal.org
November 7, 2025 - Usage of deprecated function creating dynamic properties. 1. Use php 8.3 2. Access any content that uses the language fallback 3. Access the logs · Explicit implement the properties that are being dynamic created and use array key->values when the property is on the module's classes objects