ID: 41871 User updated by: kulakov74 at yandex dot ru Reported By: kulakov74 at yandex dot ru Status: Bogus Bug Type: MySQL related Operating System: Linux / Windows PHP Version: 5.2.3 New Comment:
Well maybe, but I checked MySql API mysql_free_result() source code and there's no reference counting logic, it just frees stuff. I suppose this is PHP's mysql_free_result() implementation that checks reference count, and it was intended as a kind of service to prevent people from losing a result set while there is still another reference around. But I do not think this is really expected and people use it this way by calling mysql_free_result() first and then using the same result again from another variable. I think most people expect PHP mysql_free_result() to call MySql mysql_free_result directly whatsoever. Also, I suppose PHP might call mysql_free_result() automatically when reference count goes to 0 even before the script is over, for example if I execute an Sql-query inside a function and then return from it without saving the result PHP might call mysql_free_result() when destroying the variable. But it is not obvious that reference count check should be done at direct calls to mysql_free_result() as then I say I want it, no matter how many references I still have. Also, it is not clear which exactly variable is dereferenced from the result set as the variable passed to mysql_free_result() still exists after the call and I can use it again. If I call mysql_free_result() with the same variable again it does free the result :) Previous Comments: ------------------------------------------------------------------------ [2007-07-02 23:11:16] [EMAIL PROTECTED] This is expected result. mysql_free_result() just decreases the refcount to the result and actual freeing happens during request shutdown (if refcount to the result is 0!). ------------------------------------------------------------------------ [2007-07-02 13:12:53] kulakov74 at yandex dot ru Description: ------------ When I call mysql_free_result($Res) I expect I won't be able to use the result in calls to mysql_fetch_array() etc. But if $Res is passed by reference as a function parameter and is copied to another variable the result is not freed and I can still use it. I realize this is a VERY unlikely condition and I found it by accident (mixed 2 lines of code and got surprised to see no error). Also this might well be intentional behavior. Anyway, just in case. Reproduce code: --------------- a($Res); function a(&$Res){ $Res=mysql_query("Show Tables"); $Res1=$Res; mysql_free_result($Res); mysql_fetch_array($Res); //still works! } Expected result: ---------------- Warning: mysql_fetch_array(): 7 is not a valid MySQL result resource in Actual result: -------------- No errors ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=41871&edit=1