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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
32 + 34 = ?
Subscribe to this entry?

 
 [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: Sun May 19 12:01:30 2024 UTC