DEV Community

Cover image for PHP - Deprecation of Dynamic Properties
Damian Brdej
Damian Brdej

Posted on

PHP - Deprecation of Dynamic Properties

Recently the Deprecate dynamic properties RFC has been approved for PHP 8.2, which means that dynamic properties will not be allowed in PHP 9.0.

here's an example of declaring dynamic property:

class User {
    public $name;
}

$user = new User;

// Assigns declared property User::$name.
$user->name = "foo";

// Oops, a typo:
$user->nane = "foo";
// PHP <= 8.1: Silently creates dynamic $user->nane property.
// PHP    8.2: Raises deprecation warning, still creates dynamic property.
// PHP    9.0: Throws Error exception.
Enter fullscreen mode Exit fullscreen mode

code snippet from https://wiki.php.net/rfc/deprecate_dynamic_properties

Judging by the pace of PHP development, version 8.2 will be released in November 2022, and version 9.0 in November 2025 so we have plenty of time to prepare for this change.

In my opinion, this is a good change, it makes PHP more strict language and it will prevent mistakes and hard to find bugs.

And what do you think about this change?

Top comments (0)