🌐
PHP.Watch
php.watch › versions › 8.4 › Deprecated
`#[Deprecated]` attribute - PHP 8.4 • PHP.Watch
PHP 8.4 introduces a new PHP Attribute named #[Deprecated], that can attribute a PHP function, a class method, or a class constant as deprecated.
🌐
PHP
wiki.php.net › rfc › deprecated_attribute
PHP RFC: #[\Deprecated] Attribute
For class constants Reflection... in PHP 8.4). Calling a function will emit a E_USER_DEPRECATED error (internal functions emit E_DEPRECATED, but this error code is reserved for internal functions). Accessing a class constant will emit a E_USER_DEPRECATED error (likewise internal class constants use E_DEPRECATED). The $message given within the attribute definition ...
Discussions

PHP 8.4 polyfill for Deprecated attribute is not compatible with PHP 8.0
The PHP 8.4 polyfills have a minimum supported PHP version of PHP 7.2. In the polyfill code for the Deprecated attribute uses readonly properties, which are only available in PHP 8.1+: https://gith... More on github.com
🌐 github.com
7
October 22, 2025
deprecated - How to deprecate a function in PHP? - Stack Overflow
As of PHP 8.4, you can use #[\Deprecated] attribute. More on stackoverflow.com
🌐 stackoverflow.com
PHP 8.2 Dynamic Properties Deprecated: how to use them anyway in a compatible way - Stack Overflow
Will this RFC be also applied to PHP 8.2 onwards or is only a "sort of workaround" of this particular version? Also, do I have to apply this attribute on classes that extend the base class that internally use dynamic setters, or has it to be verbosely set in every child class? Also, is it enough to put this attribute on magic __set() or globally on the class itself? ... I would assume it applies to all versions until it's deprecated ... More on stackoverflow.com
🌐 stackoverflow.com
Why #[Deprecated] is still not a thing?
Heres the discussion about this RFC: https://externals.io/message/112554 For me it seems that there is no specific reason. It seems that the RFC was just never finished and put to vote. And without a positive vote, the pull requests get not merged. More on reddit.com
🌐 r/PHP
29
33
April 8, 2024
🌐
M
m.academy › lessons › deprecate-methods-using-attributes-php-84
Deprecate methods using attributes in PHP 8.4 - Developer Lesson
We can also pass along our custom message to this attribute with the message argument: <?php declare(strict_types=1); class FileUploader { #[Deprecated( message: "Method FileUploader::upload() is deprecated, use uploadFile() instead", )] public function upload( string $path, ): void // Upload implementation } public function uploadFile( string $path, ): void { // Improved upload implementation with validation } }
Published   April 8, 2025
🌐
PHP
php.net › manual › en › class.deprecated.php
PHP: Deprecated - Manual
Deprecated::__construct » · « AllowDynamicProperties::__construct · Preface · Language Reference · Predefined Attributes · (PHP 8 >= 8.4.0) This attribute is used to mark functionality as deprecated.
🌐
Eusonlito
eusonlito.github.io › php-changes-cheatsheet › deprecated.html
Deprecated Features in PHP 8.5, 8.4, 8.3, 8.2, 8.1, 8.0, 7.4, 7.3, 7.2, 7.1, 7.0, 5.6, 5.5, 5.4, 5.3
If a parameter with a default value is followed by a required parameter, the default value has no effect. This is deprecated as of PHP 8.0.0 and can generally be resolved by dropping the default value, without a change in functionality:
🌐
GitHub
github.com › s-damian › php-8-4-new-features › blob › main › deprecated-attribute.php
php-8-4-new-features/deprecated-attribute.php at main · s-damian/php-8-4-new-features
* Deprecated Attribute - PHP 8.4 · * · * Allowed targets: function, method, class constant. */ · class MathPhp · { // Attribute "Deprecated" cannot target property. private int $total = 0; · // Attribute "Deprecated" can target class constant.
Author   s-damian
🌐
GitHub
github.com › symfony › polyfill › issues › 551
PHP 8.4 polyfill for Deprecated attribute is not compatible with PHP 8.0 · Issue #551 · symfony/polyfill
October 22, 2025 - The PHP 8.4 polyfills have a minimum supported PHP version of PHP 7.2. In the polyfill code for the Deprecated attribute uses readonly properties, which are only available in PHP 8.1+: https://github.com/symfony/polyfill-php84/blob/1.x/Resources/stubs/Deprecated.php
Author   jrfnl
Find elsewhere
Top answer
1 of 5
15

As suggested by ADyson, the solution is to use the #[AllowDynamicProperties] attribute just above the class definition.

Classes marked with #[AllowDynamicProperties] as well as their children can continue using dynamic properties without deprecation or removal.

For classes that intentionally don't have a fixed set of properties, it's possible to either implement magic __get()/__set() or mark the class using the #[AllowDynamicProperties] attribute. Marking a class with #[AllowDynamicProperties] is fully backwards-compatible with earlier PHP versions, because prior to PHP 8.0 this would be interpreted as a comment, and the use non-existent classes as attributes is not an error.

This is a full example, as contained in this github repository that I've created to test this feature on Traits and Extended Classes

<?php
namespace App\Classes;

/**
 * Use the fully-qualified AllowDynamicProperties, otherwise the #[AllowDynamicProperties] attribute on "MyClass" WILL NOT WORK.
 */
use \AllowDynamicProperties;

#[AllowDynamicProperties]
class MyClass
{
    /**
     * Dynamic attributes will work with no deprecation warnings
     */
    public function __construct()
    {
        $this->first_name = 'George';
        $this->last_name = 'Orwell';
    }
}

class MyExtendedClass extends MyClass 
{
    /**
     * Even if "MyExtendedClass" is not using #[AllowDynamicProperties], it extends "MyClass", that is using it.
     * Dynamic attributes will work with no deprecation warnings
     */
    public function __construct()
    {
        parent::__construct();
    }
}

Other noteworthy facts:

  • If you're willing to use the #[AllowDynamicProperties] attribute in non-namespaced contexts, the fully-qualified use \AllowDynamicProperties; statement is not strictly needed (this extends the comment of user706420)
  • If you need a quick and dirty fix (for example, an old codebase) you can use the class Foo extends \stdClass as suggested by Ale DC: dynamic properties will work as expected.
2 of 5
8

replace this:

class yourClassName {

for this:

class yourClassName extends \stdClass {
🌐
PHP.Watch
php.watch › versions › 8.2 › dynamic-properties-deprecated
Dynamic Properties are deprecated - PHP 8.2 • PHP.Watch
Classes with #[AllowDynamicProperties] attribute. ... 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.
🌐
Lindevs
lindevs.com › use-deprecated-attribute-in-php-8-4
Use Deprecated Attribute in PHP 8.4 | Lindevs
December 6, 2024 - Since PHP 8.4, we can use the #[Deprecated] attribute to mark functionality as deprecated, providing a clear indication to developers that the feature s...
🌐
DEV Community
dev.to › xxzeroxx › php-8-news-attributes-3
PHP 8 News: Attributes - DEV Community
February 24, 2024 - In this example, we're using PHP's built-in Deprecated attribute to mark a function as deprecated. This will alert developers that the function will be removed in future versions, encouraging them to update their code.
🌐
Externals
externals.io › message › 112554
#[Deprecated] Attribute - Externals
I have updated the RFC for a #[Deprecated] attribute that wasn't completed for PHP 8.0 due to time constraints and I am able to restart the discussion now.
🌐
PHPStan
phpstan.org › error-identifiers › attribute.deprecated
Error Identifier: attribute.deprecated
<?php declare(strict_types = 1); /** @deprecated Use NewAttribute instead */ #[\Attribute] class OldAttribute { } #[OldAttribute] class Foo { } An attribute references a class that has been marked as deprecated.
🌐
Medium
medium.com › @parvej.code › deprecations-in-upcoming-php-8-2-and-what-you-have-to-know-1911c93d0483
Deprecation's in PHP 8.2 and What you have to know
December 9, 2022 - There are three exceptions for this deprecation. Classes with #[AllowDynamicProperties] attribute. With this new attribute introduced in PHP 8.2 you can stop PHP from emitting deprecation notice.