From: metamarkers at gmail dot com Operating system: PHP version: Irrelevant Package: Class/Object related Bug Type: Feature/Change Request Bug description:Register callbacks to an object's lifespan.
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 }); -- Edit bug report at https://bugs.php.net/bug.php?id=65719&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65719&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=65719&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65719&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=65719&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=65719&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=65719&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=65719&r=needscript Try newer version: https://bugs.php.net/fix.php?id=65719&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=65719&r=support Expected behavior: https://bugs.php.net/fix.php?id=65719&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=65719&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=65719&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=65719&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65719&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=65719&r=dst IIS Stability: https://bugs.php.net/fix.php?id=65719&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=65719&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=65719&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=65719&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=65719&r=mysqlcfg