<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/reserved.attributes.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'es',
  ),
  'this' => 
  array (
    0 => 'class.allowdynamicproperties.php',
    1 => 'AllowDynamicProperties',
    2 => 'El atributo 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' => 'es',
    'path' => 'language/predefined/attributes/allowdynamicproperties.xml',
  ),
  'history' => 
  array (
  ),
  '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);

contributors($setup);

?>
<div id="class.allowdynamicproperties" class="reference">
 <h1 class="title">El atributo AllowDynamicProperties</h1>
 

 <div class="partintro"><p class="verinfo">(PHP 8 &gt;= 8.2.0)</p>

  <div class="section" id="allowdynamicproperties.intro">
   <h2 class="title">Introducción</h2>
   <p class="simpara">
    Este atributo se utiliza para marcar clases que permiten
    <a href="language.oop5.properties.php#language.oop5.properties.dynamic-properties" class="link">propiedades dinámicas</a>.
   </p>
   <blockquote class="note"><p><strong class="note">Nota</strong>: 
    <span class="simpara">
     Aunque los atributos en sí no se heredan, el efecto del atributo
     <code class="literal">AllowDynamicProperties</code> <em>sí</em>
     se hereda. Las clases hijas de una clase marcada con este atributo también
     permitirán propiedades dinámicas, incluso si no declaran el atributo
     explícitamente.
    </span>
   </p></blockquote>
  </div>

  <div class="section" id="allowdynamicproperties.synopsis">
   <h2 class="title">Sinopsis de la Clase</h2>

   <div class="classsynopsis"><div class="classsynopsisinfo">
    
     <span class="attribute"><a href="class.attribute.php">#[\Attribute]</a> </span><br>
     <span class="modifier">final</span>
     <span class="modifier">class</span> <strong class="classname"><strong class="classname">AllowDynamicProperties</strong></strong>
     {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Métodos */</div>
    <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="allowdynamicproperties.construct.php" class="methodname">__construct</a></span>()</div>

   }</div>

  </div>

  <div class="section">
   <h2 class="title">Ejemplos</h2>
   <p class="simpara">
    Las propiedades dinámicas están deprecadas a partir de PHP 8.2.0,
    por lo que usarlas sin marcar la clase con este atributo emitirá
    un aviso de deprecación.
   </p>
   <div class="example" id="example-1">
    <p><strong>Ejemplo #1 AllowDynamicProperties con propiedad inexistente</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">DefaultBehaviour </span><span style="color: #007700">{ }<br /><br />#[</span><span style="color: #0000BB">\AllowDynamicProperties</span><span style="color: #007700">]<br />class </span><span style="color: #0000BB">ClassAllowsDynamicProperties </span><span style="color: #007700">{ }<br /><br /></span><span style="color: #0000BB">$o1 </span><span style="color: #007700">= new </span><span style="color: #0000BB">DefaultBehaviour</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$o2 </span><span style="color: #007700">= new </span><span style="color: #0000BB">ClassAllowsDynamicProperties</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$o1</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">nonExistingProp </span><span style="color: #007700">= </span><span style="color: #0000BB">true</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$o2</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">nonExistingProp </span><span style="color: #007700">= </span><span style="color: #0000BB">true</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Resultado del ejemplo anterior en PHP 8.2:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Deprecated: Creation of dynamic property DefaultBehaviour::$nonExistingProp is deprecated in file on line 10
</pre></div>
    </div>
   </div>
   <div class="example" id="example-2">
    <p><strong>Ejemplo #2 AllowDynamicProperties con propiedad inexistente en clase heredada</strong></p>
    <div class="example-contents">
     <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">DefaultBehaviour </span><span style="color: #007700">{ }<br /><br />#[</span><span style="color: #0000BB">\AllowDynamicProperties</span><span style="color: #007700">]<br />class </span><span style="color: #0000BB">ClassAllowsDynamicProperties </span><span style="color: #007700">{ }<br /><br />class </span><span style="color: #0000BB">InheritedClassAllowsDynamicProperties </span><span style="color: #007700">extends </span><span style="color: #0000BB">ClassAllowsDynamicProperties </span><span style="color: #007700">{ }<br /><br /></span><span style="color: #0000BB">$o1 </span><span style="color: #007700">= new </span><span style="color: #0000BB">DefaultBehaviour</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$o2 </span><span style="color: #007700">= new </span><span style="color: #0000BB">InheritedClassAllowsDynamicProperties</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$o1</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">nonExistingProp </span><span style="color: #007700">= </span><span style="color: #0000BB">true</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$o2</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">nonExistingProp </span><span style="color: #007700">= </span><span style="color: #0000BB">true</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Resultado del ejemplo anterior en PHP 8.2:</p></div>
    <div class="example-contents screen">
     <div class="cdata"><pre>
Deprecated: Creation of dynamic property DefaultBehaviour::$nonExistingProp is deprecated in file on line 12
</pre></div>
    </div>
   </div>
  </div>

  <div class="section" id="allowdynamicproperties.seealso">
   <h2 class="title">Ver también</h2>
   <p class="simpara"><a href="language.attributes.php" class="link">Visión general de los atributos</a></p>
  </div>

 </div>

 




 


<h2>Tabla de contenidos</h2><ul class="chunklist chunklist_reference"><li><a href="allowdynamicproperties.construct.php">AllowDynamicProperties::__construct</a> — Construye una nueva instancia del atributo AllowDynamicProperties</li></ul>
</div>
<?php manual_footer($setup); ?>