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?

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs