PHP 8.4.0 RC4 available for testing

The AllowDynamicProperties attribute

(PHP 8 >= 8.2.0)

Вступ

This attribute is used to mark classes that allow dynamic properties.

Короткий огляд класу

final class AllowDynamicProperties {
/* Методи */
public __construct()
}

Приклади

Dynamic properties are deprecated as of PHP 8.2.0, thus using them without marking the class with this attribute will emit a deprecation notice.

<?php
class DefaultBehaviour { }

#[
\AllowDynamicProperties]
class
ClassAllowsDynamicProperties { }

$o1 = new DefaultBehaviour();
$o2 = new ClassAllowsDynamicProperties();

$o1->nonExistingProp = true;
$o2->nonExistingProp = true;
?>

В PHP 8.2 поданий вище приклад виведе:

Deprecated: Creation of dynamic property DefaultBehaviour::$nonExistingProp is deprecated in file on line 10

Прогляньте також

Attributes overview

Зміст

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top