ID: 32724 Updated by: [EMAIL PROTECTED] Reported By: victor-php at boivie dot com Status: Wont fix Bug Type: Feature/Change Request Operating System: Not important PHP Version: 5.0.4 New Comment:
The XXX_free and XXX_close functions are redundant and, IMO, potentially confusing. Resource types in PHP are reference counted and so are automatically freed when the refcount falls to zero. Resources are typically contained within a zval that has its own refcount. Variable assignments bump the zval refcount and not the resource refcount. This is ok for most resources; when the zval refcount falls to zero, it releases the single ref it held on the resource and cleans it up. Similarly, the XXX_free functions perform the same action. When you have a more complicated scenario, with the resource having more than one reference on it, calling XXX_free will delete only one reference and not really really free the resource. This is counter-intuitive; you would expect that call to free it. So, it is better to not have functions that imply such a final act. Another argument is that $foo = null; is faster to compile and run than making a function call to foo_free($foo); In the specific case of sqlite, there should be no problem with a higher than 1 refcount on a resource, so in theory the function could be added. If you add it, people will start using it, and that will then prompt some backwards compatibility problems in the code that they are writing. Since we're focusing on PDO for the future, I'd very much prefer it if we didn't add this function to the sqlite extension. --Wez (the primary author of the sqlite extension) Previous Comments: ------------------------------------------------------------------------ [2005-04-18 07:19:44] victor-php at boivie dot com I respect your opinion, but might I ask you _what_ your pet hate is? The SQLite extension? The *_free_result-functions? If it is just personal and not for the good of the PHP language, I might consider implementing it myself (sending a patch to the php-dev group) ------------------------------------------------------------------------ [2005-04-18 01:11:51] [EMAIL PROTECTED] This is actually one of my pet hates in PHP. I won't be implementing it. ------------------------------------------------------------------------ [2005-04-17 14:54:14] [EMAIL PROTECTED] moving to the right category.. ------------------------------------------------------------------------ [2005-04-16 09:10:20] victor-php at boivie dot com That actually produces correct results. So setting a resource to null frees the resource? http://se2.php.net/manual/en/language.types.resource.php mentions that "Due to the reference-counting system ... it is automatically detected when a resource is no longer referred to .. all resources that were in use for this resource are made free by the garbage collector. For this reason, it is rarely ever necessary to free the memory manually by using some free_result function." So it is actually noted in the manual. However, for symmetry in the PHP language, I still think it's a good idea to have a sqlite_free_result that does exactly this, as there is for many other databases (every other?). It would be more intuitive anyway - what do you think? Thanks for your help! ------------------------------------------------------------------------ [2005-04-16 00:23:56] [EMAIL PROTECTED] $res = null; not good enough? ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/32724 -- Edit this bug report at http://bugs.php.net/?id=32724&edit=1
