php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #65719 Register callbacks to an object's lifespan.
Submitted: 2013-09-20 04:04 UTC Modified: 2013-09-20 10:38 UTC
From: metamarkers at gmail dot com Assigned:
Status: Wont fix Package: Class/Object related
PHP Version: Irrelevant OS:
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: metamarkers at gmail dot com
New email:
PHP Version: OS:

 

 [2013-09-20 04:04 UTC] metamarkers at gmail dot com
Description:
------------
There already exists __destruct(), but if you need to clean up mappings that use 
an object's identifier to cache results etc, there isn't a smooth way of doing 
this.

It would be nice to tie a callback to an object's lifespan.

The catch would of course be that you can't reference the object in the callback 
because of circular references, or maybe you can, I'm not that intimate with 
PHP's garbage collection.

Test script:
---------------
$x = (object)[];
register_destructor($x,function($x){
    // extra cleanup operations with $x,
    // or instead an spl_object_hash() could be precalculated and closed over
    // if using $x would cause circular death
});


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-09-20 10:38 UTC] nikic@php.net
-Status: Open +Status: Wont fix
 [2013-09-20 10:38 UTC] nikic@php.net
I think you're looking for a WeakMap here: http://de2.php.net/manual/en/class.weakmap.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 22:01:29 2024 UTC