<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/language.oop5.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'language.oop5.decon.php',
    1 => 'Constructors and Destructors',
    2 => 'Constructors and Destructors',
  ),
  'up' => 
  array (
    0 => 'language.oop5.php',
    1 => 'Classi e Oggetti',
  ),
  'prev' => 
  array (
    0 => 'language.oop5.autoload.php',
    1 => 'Caricamento automatico delle classi',
  ),
  'next' => 
  array (
    0 => 'language.oop5.visibility.php',
    1 => 'Visibility',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'language/oop5/decon.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="language.oop5.decon" class="sect1">
  <h2 class="title">Constructors and Destructors</h2>

  <div class="sect2" id="language.oop5.decon.constructor">
   <h3 class="title">Constructor</h3>
   <div class="methodsynopsis dc-description" id="object.construct">
    <span class="methodname"><strong>__construct</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">...$values</code><span class="initializer"> = &quot;&quot;</span></span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

   <p class="para">
    PHP allows developers to declare constructor methods for classes.
    Classes which have a constructor method call this method on each
    newly-created object, so it is suitable for any initialization that the
    object may need before it is used.
   </p>
   <blockquote class="note"><p><strong class="note">Nota</strong>: 
    <span class="simpara">
     Parent constructors are not called implicitly if the child class defines
     a constructor.  In order to run a parent constructor, a call to
     <span class="function"><strong>parent::__construct()</strong></span> within the child constructor is
     required. If the child does not define a constructor then it may be inherited
     from the parent class just like a normal class method (if it was not declared
     as private).
    </span>
   </p></blockquote>
   <div class="example" id="example-1">
    <p><strong>Example #1 Constructors in inheritance</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">BaseClass </span><span style="color: #007700">{<br />    function </span><span style="color: #0000BB">__construct</span><span style="color: #007700">() {<br />        print </span><span style="color: #DD0000">"In BaseClass constructor\n"</span><span style="color: #007700">;<br />    }<br />}<br /><br />class </span><span style="color: #0000BB">SubClass </span><span style="color: #007700">extends </span><span style="color: #0000BB">BaseClass </span><span style="color: #007700">{<br />    function </span><span style="color: #0000BB">__construct</span><span style="color: #007700">() {<br />        </span><span style="color: #0000BB">parent</span><span style="color: #007700">::</span><span style="color: #0000BB">__construct</span><span style="color: #007700">();<br />        print </span><span style="color: #DD0000">"In SubClass constructor\n"</span><span style="color: #007700">;<br />    }<br />}<br /><br />class </span><span style="color: #0000BB">OtherSubClass </span><span style="color: #007700">extends </span><span style="color: #0000BB">BaseClass </span><span style="color: #007700">{<br />    </span><span style="color: #FF8000">// inherits BaseClass's constructor<br /></span><span style="color: #007700">}<br /><br /></span><span style="color: #FF8000">// In BaseClass constructor<br /></span><span style="color: #0000BB">$obj </span><span style="color: #007700">= new </span><span style="color: #0000BB">BaseClass</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">// In BaseClass constructor<br />// In SubClass constructor<br /></span><span style="color: #0000BB">$obj </span><span style="color: #007700">= new </span><span style="color: #0000BB">SubClass</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">// In BaseClass constructor<br /></span><span style="color: #0000BB">$obj </span><span style="color: #007700">= new </span><span style="color: #0000BB">OtherSubClass</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
   <p class="para">
    Unlike other methods, <a href="language.oop5.decon.php#object.construct" class="link">__construct()</a>
    is exempt from the usual
    <a href="language.oop5.basic.php#language.oop.lsp" class="link">signature compatibility rules</a>
    when being extended.
   </p>
   <p class="para">
    Constructors are ordinary methods which are called during the instantiation of their
    corresponding object.  As such, they may define an arbitrary number of arguments, which
    may be required, may have a type, and may have a default value. Constructor arguments
    are called by placing the arguments in parentheses after the class name.
   </p>
   <div class="example" id="example-2">
    <p><strong>Example #2 Using constructor arguments</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">Point </span><span style="color: #007700">{<br />    protected </span><span style="color: #0000BB">int $x</span><span style="color: #007700">;<br />    protected </span><span style="color: #0000BB">int $y</span><span style="color: #007700">;<br /><br />    public function </span><span style="color: #0000BB">__construct</span><span style="color: #007700">(</span><span style="color: #0000BB">int $x</span><span style="color: #007700">, </span><span style="color: #0000BB">int $y </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">) {<br />        </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">x </span><span style="color: #007700">= </span><span style="color: #0000BB">$x</span><span style="color: #007700">;<br />        </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">y </span><span style="color: #007700">= </span><span style="color: #0000BB">$y</span><span style="color: #007700">;<br />    }<br />}<br /><br /></span><span style="color: #FF8000">// Pass both parameters.<br /></span><span style="color: #0000BB">$p1 </span><span style="color: #007700">= new </span><span style="color: #0000BB">Point</span><span style="color: #007700">(</span><span style="color: #0000BB">4</span><span style="color: #007700">, </span><span style="color: #0000BB">5</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">// Pass only the required parameter. $y will take its default value of 0.<br /></span><span style="color: #0000BB">$p2 </span><span style="color: #007700">= new </span><span style="color: #0000BB">Point</span><span style="color: #007700">(</span><span style="color: #0000BB">4</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">// With named parameters (as of PHP 8.0):<br /></span><span style="color: #0000BB">$p3 </span><span style="color: #007700">= new </span><span style="color: #0000BB">Point</span><span style="color: #007700">(</span><span style="color: #0000BB">y</span><span style="color: #007700">: </span><span style="color: #0000BB">5</span><span style="color: #007700">, </span><span style="color: #0000BB">x</span><span style="color: #007700">: </span><span style="color: #0000BB">4</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
   <p class="para">
    If a class has no constructor, or the constructor has no required arguments, the parentheses
    may be omitted.
   </p>
   <div class="sect3">
    <h4 class="title">Old-style constructors</h4>
    <p class="para">
     Prior to PHP 8.0.0, classes in the global namespace will interpret a method named
     the same as the class as an old-style constructor.  That syntax is deprecated,
     and will result in an <strong><code><a href="errorfunc.constants.php#constant.e-deprecated">E_DEPRECATED</a></code></strong> error but still call that function as a constructor.
     If both <a href="language.oop5.decon.php#object.construct" class="link">__construct()</a> and a same-name method are
     defined, <a href="language.oop5.decon.php#object.construct" class="link">__construct()</a> will be called.
    </p>
    <p class="para">
     In namespaced classes, or any class as of PHP 8.0.0, a method named
     the same as the class never has any special meaning.
    </p>
    <p class="para">Always use <a href="language.oop5.decon.php#object.construct" class="link">__construct()</a> in new code.
    </p>
   </div>
   <div class="sect3" id="language.oop5.decon.constructor.promotion">
    <h4 class="title">Constructor Promotion</h4>
    <p class="para">
     As of PHP 8.0.0, constructor parameters may also be promoted to correspond to an
     object property.  It is very common for constructor parameters to be assigned to
     a property in the constructor but otherwise not operated upon.  Constructor promotion
     provides a short-hand for that use case.  The example above could be rewritten as the following.
    </p>
    <div class="example" id="example-3">
     <p><strong>Example #3 Using constructor property promotion</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">Point </span><span style="color: #007700">{<br />    public function </span><span style="color: #0000BB">__construct</span><span style="color: #007700">(protected </span><span style="color: #0000BB">int $x</span><span style="color: #007700">, protected </span><span style="color: #0000BB">int $y </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">) {<br />    }<br />}</span></span></code></div>
     </div>

    </div>
    <p class="para">
     When a constructor argument includes a modifier, PHP will interpret it as
     both an object property and a constructor argument, and assign the argument value to
     the property.  The constructor body may then be empty or may contain other statements.
     Any additional statements will be executed after the argument values have been assigned
     to the corresponding properties.
    </p>
    <p class="para">
     Not all arguments need to be promoted. It is possible to mix and match promoted and not-promoted
     arguments, in any order.  Promoted arguments have no impact on code calling the constructor.
    </p>
    <blockquote class="note"><p><strong class="note">Nota</strong>: 
     <p class="para">
      Using a <a href="language.oop5.visibility.php" class="link">visibility modifier</a> (<code class="literal">public</code>,
      <code class="literal">protected</code> or <code class="literal">private</code>) is the most likely way to apply property
      promotion, but any other single modifier (such as <code class="literal">readonly</code>) will have the same effect.
     </p>
    </p></blockquote>
    <blockquote class="note"><p><strong class="note">Nota</strong>: 
     <p class="para">
      Object properties may not be typed <span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span> due to engine ambiguity that would
      introduce. Promoted arguments, therefore, may not be typed <span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span> either. Any
      other <a href="language.types.declarations.php" class="link">type declaration</a> is permitted, however.
     </p>
    </p></blockquote>
    <blockquote class="note"><p><strong class="note">Nota</strong>: 
     <p class="para">
      As promoted properties are desugared to both a property as well as a function parameter, any
      and all naming restrictions for both properties as well as parameters apply.
     </p>
    </p></blockquote>
    <blockquote class="note"><p><strong class="note">Nota</strong>: 
     <p class="para">
      <a href="language.attributes.php" class="link">Attributes</a> placed on a
      promoted constructor argument will be replicated to both the property
      and argument.  Default values on a promoted constructor argument will be replicated only to the argument and not the property.
     </p>
    </p></blockquote>
   </div>

   <div class="sect3" id="language.oop5.decon.constructor.new">
    <h4 class="title">New in initializers</h4>
    <p class="para">
     As of PHP 8.1.0, objects can be used as default parameter values,
     static variables, and global constants, as well as in attribute arguments.
     Objects can also be passed to <span class="function"><a href="function.define.php" class="function">define()</a></span> now.
    </p>
    <blockquote class="note"><p><strong class="note">Nota</strong>: 
     <p class="para">
      The use of a dynamic or non-string class name or an anonymous class is not allowed.
      The use of argument unpacking is not allowed.
      The use of unsupported expressions as arguments is not allowed.
     </p>
    </p></blockquote>
    <div class="example" id="example-4">
     <p><strong>Example #4 Using new in initializers</strong></p>
     <div class="example-contents">
<div class="annotation-non-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">// All allowed:<br /></span><span style="color: #007700">static </span><span style="color: #0000BB">$x </span><span style="color: #007700">= new </span><span style="color: #0000BB">Foo</span><span style="color: #007700">;<br /><br />const </span><span style="color: #0000BB">C </span><span style="color: #007700">= new </span><span style="color: #0000BB">Foo</span><span style="color: #007700">;<br /> <br />function </span><span style="color: #0000BB">test</span><span style="color: #007700">(</span><span style="color: #0000BB">$param </span><span style="color: #007700">= new </span><span style="color: #0000BB">Foo</span><span style="color: #007700">) {}<br /> <br />#[</span><span style="color: #0000BB">AnAttribute</span><span style="color: #007700">(new </span><span style="color: #0000BB">Foo</span><span style="color: #007700">)]<br />class </span><span style="color: #0000BB">Test </span><span style="color: #007700">{<br />    public function </span><span style="color: #0000BB">__construct</span><span style="color: #007700">(<br />        public </span><span style="color: #0000BB">$prop </span><span style="color: #007700">= new </span><span style="color: #0000BB">Foo</span><span style="color: #007700">,<br />    ) {}<br />}<br /><br /></span><span style="color: #FF8000">// All not allowed (compile-time error):<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">test</span><span style="color: #007700">(<br />    </span><span style="color: #0000BB">$a </span><span style="color: #007700">= new (</span><span style="color: #0000BB">CLASS_NAME_CONSTANT</span><span style="color: #007700">)(), </span><span style="color: #FF8000">// dynamic class name<br />    </span><span style="color: #0000BB">$b </span><span style="color: #007700">= new class {}, </span><span style="color: #FF8000">// anonymous class<br />    </span><span style="color: #0000BB">$c </span><span style="color: #007700">= new </span><span style="color: #0000BB">A</span><span style="color: #007700">(...[]), </span><span style="color: #FF8000">// argument unpacking<br />    </span><span style="color: #0000BB">$d </span><span style="color: #007700">= new </span><span style="color: #0000BB">B</span><span style="color: #007700">(</span><span style="color: #0000BB">$abc</span><span style="color: #007700">), </span><span style="color: #FF8000">// unsupported constant expression<br /></span><span style="color: #007700">) {}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
     </div>

    </div>
   </div>
   
   <div class="sect3" id="language.oop5.decon.constructor.static">
    <h4 class="title">Static creation methods</h4>
    <p class="para">
     PHP only supports a single constructor per class.  In some cases, however, it may be
     desirable to allow an object to be constructed in different ways with different inputs.
     The recommended way to do so is by using static methods as constructor wrappers.
    </p>
    <div class="example" id="example-5">
     <p><strong>Example #5 Using static creation methods</strong></p>
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$some_json_string </span><span style="color: #007700">= </span><span style="color: #DD0000">'{ "id": 1004, "name": "Elephpant" }'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$some_xml_string </span><span style="color: #007700">= </span><span style="color: #DD0000">"&lt;animal&gt;&lt;id&gt;1005&lt;/id&gt;&lt;name&gt;Elephpant&lt;/name&gt;&lt;/animal&gt;"</span><span style="color: #007700">;<br /><br />class </span><span style="color: #0000BB">Product </span><span style="color: #007700">{<br /><br />    private ?</span><span style="color: #0000BB">int $id</span><span style="color: #007700">;<br />    private ?</span><span style="color: #0000BB">string $name</span><span style="color: #007700">;<br /><br />    private function </span><span style="color: #0000BB">__construct</span><span style="color: #007700">(?</span><span style="color: #0000BB">int $id </span><span style="color: #007700">= </span><span style="color: #0000BB">null</span><span style="color: #007700">, ?</span><span style="color: #0000BB">string $name </span><span style="color: #007700">= </span><span style="color: #0000BB">null</span><span style="color: #007700">) {<br />        </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">id </span><span style="color: #007700">= </span><span style="color: #0000BB">$id</span><span style="color: #007700">;<br />        </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">name </span><span style="color: #007700">= </span><span style="color: #0000BB">$name</span><span style="color: #007700">;<br />    }<br /><br />    public static function </span><span style="color: #0000BB">fromBasicData</span><span style="color: #007700">(</span><span style="color: #0000BB">int $id</span><span style="color: #007700">, </span><span style="color: #0000BB">string $name</span><span style="color: #007700">): static {<br />        </span><span style="color: #0000BB">$new </span><span style="color: #007700">= new static(</span><span style="color: #0000BB">$id</span><span style="color: #007700">, </span><span style="color: #0000BB">$name</span><span style="color: #007700">);<br />        return </span><span style="color: #0000BB">$new</span><span style="color: #007700">;<br />    }<br /><br />    public static function </span><span style="color: #0000BB">fromJson</span><span style="color: #007700">(</span><span style="color: #0000BB">string $json</span><span style="color: #007700">): static {<br />        </span><span style="color: #0000BB">$data </span><span style="color: #007700">= </span><span style="color: #0000BB">json_decode</span><span style="color: #007700">(</span><span style="color: #0000BB">$json</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">);<br />        return new static(</span><span style="color: #0000BB">$data</span><span style="color: #007700">[</span><span style="color: #DD0000">'id'</span><span style="color: #007700">], </span><span style="color: #0000BB">$data</span><span style="color: #007700">[</span><span style="color: #DD0000">'name'</span><span style="color: #007700">]);<br />    }<br /><br />    public static function </span><span style="color: #0000BB">fromXml</span><span style="color: #007700">(</span><span style="color: #0000BB">string $xml</span><span style="color: #007700">): static {<br />        </span><span style="color: #0000BB">$data </span><span style="color: #007700">= </span><span style="color: #0000BB">simplexml_load_string</span><span style="color: #007700">(</span><span style="color: #0000BB">$xml</span><span style="color: #007700">);<br />        </span><span style="color: #0000BB">$new </span><span style="color: #007700">= new static();<br />        </span><span style="color: #0000BB">$new</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">id </span><span style="color: #007700">= (int) </span><span style="color: #0000BB">$data</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">id</span><span style="color: #007700">;<br />        </span><span style="color: #0000BB">$new</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">name </span><span style="color: #007700">= </span><span style="color: #0000BB">$data</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">name</span><span style="color: #007700">;<br />        return </span><span style="color: #0000BB">$new</span><span style="color: #007700">;<br />    }<br />}<br /><br /></span><span style="color: #0000BB">$p1 </span><span style="color: #007700">= </span><span style="color: #0000BB">Product</span><span style="color: #007700">::</span><span style="color: #0000BB">fromBasicData</span><span style="color: #007700">(</span><span style="color: #0000BB">5</span><span style="color: #007700">, </span><span style="color: #DD0000">'Widget'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$p2 </span><span style="color: #007700">= </span><span style="color: #0000BB">Product</span><span style="color: #007700">::</span><span style="color: #0000BB">fromJson</span><span style="color: #007700">(</span><span style="color: #0000BB">$some_json_string</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$p3 </span><span style="color: #007700">= </span><span style="color: #0000BB">Product</span><span style="color: #007700">::</span><span style="color: #0000BB">fromXml</span><span style="color: #007700">(</span><span style="color: #0000BB">$some_xml_string</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$p1</span><span style="color: #007700">, </span><span style="color: #0000BB">$p2</span><span style="color: #007700">, </span><span style="color: #0000BB">$p3</span><span style="color: #007700">);</span></span></code></div>
     </div>

    </div>
    <p class="para">
     The constructor may be made private or protected to prevent it from being called externally.
     If so, only a static method will be able to instantiate the class. Because they are in the
     same class definition they have access to private methods, even if not of the same object
     instance. The private constructor is optional and may or may not make sense depending on
     the use case.
    </p>
    <p class="para">
     The three public static methods then demonstrate different ways of instantiating the object.
    </p>
    <ul class="simplelist">
     <li><code class="code">fromBasicData()</code> takes the exact parameters that are needed, then creates the
      object by calling the constructor and returning the result.</li>
     <li><code class="code">fromJson()</code> accepts a JSON string and does some pre-processing on it itself
     to convert it into the format desired by the constructor. It then returns the new object.</li>
     <li><code class="code">fromXml()</code> accepts an XML string, preprocesses it, and then creates a bare
     object.  The constructor is still called, but as all of the parameters are optional the method
     skips them.  It then assigns values to the object properties directly before returning the result.</li>
    </ul>
    <p class="para">
     In all three cases, the <code class="code">static</code> keyword is translated into the name of the class the code is in.
     In this case, <code class="code">Product</code>.
    </p>
   </div>
  </div>
  <div class="sect2" id="language.oop5.decon.destructor">
   <h3 class="title">Destructor</h3>
   <div class="methodsynopsis dc-description" id="object.destruct">
    <span class="methodname"><strong>__destruct</strong></span>(): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

   <p class="para">
    PHP possesses a destructor concept similar to that of other
    object-oriented languages, such as C++. The destructor method will be
    called as soon as there are no other references to a particular object,
    or in any order during the shutdown sequence.
   </p>
   <div class="example" id="example-6">
    <p><strong>Example #6 Destructor Example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">class </span><span style="color: #0000BB">MyDestructableClass <br /></span><span style="color: #007700">{<br />    function </span><span style="color: #0000BB">__construct</span><span style="color: #007700">() {<br />        print </span><span style="color: #DD0000">"In constructor\n"</span><span style="color: #007700">;<br />    }<br /><br />    function </span><span style="color: #0000BB">__destruct</span><span style="color: #007700">() {<br />        print </span><span style="color: #DD0000">"Destroying " </span><span style="color: #007700">. </span><span style="color: #0000BB">__CLASS__ </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />    }<br />}<br /><br /></span><span style="color: #0000BB">$obj </span><span style="color: #007700">= new </span><span style="color: #0000BB">MyDestructableClass</span><span style="color: #007700">();</span></span></code></div>
    </div>

   </div>
   <p class="para">
    Like constructors, parent destructors will not be called implicitly by
    the engine. In order to run a parent destructor, one would have to
    explicitly call <span class="function"><strong>parent::__destruct()</strong></span> in the destructor
    body. Also like constructors, a child class may inherit the parent&#039;s
    destructor if it does not implement one itself.
   </p>
   <p class="para">
    The destructor will be called even if script execution is stopped using
    <span class="function"><a href="function.exit.php" class="function">exit()</a></span>. Calling <span class="function"><a href="function.exit.php" class="function">exit()</a></span> in a destructor
    will prevent the remaining shutdown routines from executing.
   </p>
   <p class="para">
    If a destructor creates new references to its object, it will not be called
    a second time when the reference count reaches zero again or during the
    shutdown sequence.
   </p>
   <p class="para">
    As of PHP 8.4.0, when
    <a href="features.gc.collecting-cycles.php" class="link">cycle collection</a>
    occurs during the execution of a
    <a href="language.fibers.php" class="link">Fiber</a>, the destructors of objects
    scheduled for collection are executed in a separate Fiber, called the
    <code class="literal">gc_destructor_fiber</code>.
    If this Fiber is suspended, a new one will be created to execute any
    remaining destructors.
    The previous <code class="literal">gc_destructor_fiber</code> will no longer be
    referenced by the garbage collector and may be collected if it is not
    referenced elsewhere.
    Objects whose destructor are suspended will not be collected until the
    destructor returns or the Fiber itself is collected.
   </p>
   <blockquote class="note"><p><strong class="note">Nota</strong>: 
    <p class="para">
     Destructors called during the script shutdown have HTTP headers already
     sent. The working directory in the script shutdown phase can be different
     with some SAPIs (e.g. Apache).
    </p>
   </p></blockquote>
   <blockquote class="note"><p><strong class="note">Nota</strong>: 
    <p class="para">
     Attempting to throw an exception from a destructor (called in the time of
     script termination) causes a fatal error.
    </p>
   </p></blockquote>
  </div>

 </div><?php manual_footer($setup); ?>