php / php/php-src

Creation of dynamic property is deprecated !

Open
#12,694 19 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The following code ( This should never happen when I'm using magic methods, but unfortunately it does happen sometimes ):

<?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;

Result:

3

But sometimes when the number of such requests increases, I receive the following warning :

Creation of dynamic property Content::$sequence is deprecated 18
PHP Version

PHP 8.2.11

Operating System

Linux

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the PHP 8.2.11 reproduction from the issue on Linux and compare the magic-method accesses with the reported dynamic-property warning. Trace the runtime handling of __get, __set, and compound assignment to determine where the warning originates. Done should include a confirmed explanation and a regression test or clearly defined behavior change.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.