DEV Community

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

Posted on

2

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?

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay