php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79586 Destructor is not called again if the previous attempt kept the object alive
Submitted: 2020-05-11 11:32 UTC Modified: 2020-05-11 12:06 UTC
From: michael dot vorisek at email dot cz Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.4.5 OS: any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: michael dot vorisek at email dot cz
New email:
PHP Version: OS:

 

 [2020-05-11 11:32 UTC] michael dot vorisek at email dot cz
Description:
------------
Destructor has to be called on every attempt to release the object.

Test script:
---------------
class Registry {
  public static $v;
}

$v = new class() extends \stdClass {
  public function __destruct() {
    var_dump($this);
    Registry::$v = $this;
    echo 'destroyed' . "\n";
  }
};

unset($v);
var_dump(Registry::$v);
Registry::$v = null; // unset 2nd time

Expected result:
----------------
object(class@anonymous)#17 (0) {
}
destroyed
object(class@anonymous)#17 (0) {
}
object(class@anonymous)#17 (0) {
}
destroyed

Actual result:
--------------
object(class@anonymous)#17 (0) {
}
destroyed
object(class@anonymous)#17 (0) {
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-05-11 12:06 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2020-05-11 12:06 UTC] nikic@php.net
Destructor must be called at most once.
 [2020-05-11 13:08 UTC] michael dot vorisek at email dot cz
Why, is this not a valid usecase?

a) not destructing the object is fully supported already
b) if destructor does not prevent the destructions (like in the example by referencing $this to something alive), it will never be actually called twice, thus no BC break
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 05:01:33 2025 UTC