From:             
Operating system: Windows XP (Irrelevant)
PHP version:      5.3.2
Package:          Variables related
Bug Type:         Feature/Change Request
Bug description:post 5.3 - keyword: delete, "force destruct"

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 bug report at http://bugs.php.net/bug.php?id=52243&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=52243&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=52243&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=52243&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=52243&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=52243&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=52243&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=52243&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=52243&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=52243&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=52243&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=52243&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=52243&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=52243&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=52243&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=52243&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=52243&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=52243&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=52243&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=52243&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=52243&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=52243&r=mysqlcfg

Reply via email to