Edit report at http://bugs.php.net/bug.php?id=52243&edit=1
ID: 52243 Updated by: johan...@php.net Reported by: mazdak1 at telia dot com Summary: post 5.3 - keyword: delete, "force destruct" -Status: Open +Status: Bogus Type: Feature/Change Request Package: Variables related Operating System: Windows XP (Irrelevant) PHP Version: 5.3.2 Block user comment: N New Comment: Adding such a method would give us tons of errors from users destroying their objects and getting fatal Errors somewhere far away. It is better if you add a custom "invalidate" method to your classes where this is needed and track that ourself to react gracefully. Previous Comments: ------------------------------------------------------------------------ [2010-07-04 09:28:23] mazdak1 at telia dot com Description: ------------ Currently, it is impossible to force destruct/delete/destroy an object or any variable for that matter. Instead, you must unset all references until ref_count is at 0, at which point the variable/object is destructed/removed from memory. This works is fine as long as you know where all references are, but not if you don't. And this can happen e.g: when you're a lib developer and have to destruct something that the developer might reference several times, or if you're using a Singleton with a "destroy" method. Therefore, I propose a new language construct called "delete" (or some other fancy name), which deletes the variable immediately with all it's references and calling destructor if object & available. Having both unset & delete at your disposal would give you great freedom, both are useful for different situations. Test script: --------------- See: http://pastebin.com/pGdsed5M Note: as long as variables are in the same scope, all will be nulled with: <?php $a = 1; $b =& $a; $c =& $a; $a = null; ?> But this does not satisfy situations where references may be spread over many scopes. "pseudocode" of what delete($x) should do: $referencing_x = get_references_to($x); foreach($referencing_x as $ref) { $ref = null; } unset($x); Expected result: ---------------- With "delete" keyword implemented: ---------------------------------- A destructed Notice: Undefined variable: a in D:\Programming\UV\public\TEST\delete.php on line 48 NULL NULL NULL Actual result: -------------- With unset: ----------- Notice: Undefined variable: a in D:\Programming\UV\public\TEST\delete.php on line 52 NULL object(A)#30 (0) { } object(A)#30 (0) { } A destructed ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52243&edit=1