array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'pt_BR', ), 'this' => array ( 0 => 'class.allowdynamicproperties.php', 1 => 'AllowDynamicProperties', ), 'up' => array ( 0 => 'reserved.attributes.php', 1 => 'Atributos Predefinidos', ), 'prev' => array ( 0 => 'attribute.construct.php', 1 => 'Attribute::__construct', ), 'next' => array ( 0 => 'allowdynamicproperties.construct.php', 1 => 'AllowDynamicProperties::__construct', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'pt_BR', 'path' => 'language/predefined/attributes/allowdynamicproperties.xml', ), 'extra_header_links' => array ( 'rel' => 'alternate', 'href' => '/manual/en/feeds/class.allowdynamicproperties.atom', 'type' => 'application/atom+xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 8 >= 8.2.0)
Este atributo é usado para marcar classes que permitem propriedades dinâmicas.
As propriedades dinâmicas foram descontinuadas a partir do PHP 8.2.0, portanto, usá-las sem marcar a classe com este atributo emitirá um aviso de descontinuação.
<?php
class DefaultBehaviour { }
#[\AllowDynamicProperties]
class ClassAllowsDynamicProperties { }
$o1 = new DefaultBehaviour();
$o2 = new ClassAllowsDynamicProperties();
$o1->nonExistingProp = true;
$o2->nonExistingProp = true;
?>
Saída do exemplo acima no PHP 8.2:
Deprecated: Creation of dynamic property DefaultBehaviour::$nonExistingProp is deprecated in file on line 10