Skip to content

Creation of dynamic property is deprecated ! #12694

@Tak-Pesar

Description

@Tak-Pesar

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions