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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 17:01:34 2024 UTC