Edit report at https://bugs.php.net/bug.php?id=63486&edit=1
ID: 63486 Comment by: hugh dot messenger at gmail dot com Reported by: der...@php.net Summary: mysqli_free_result leave the resource variable in a messy state Status: Verified Type: Bug Package: MySQLi related PHP Version: 5.4.8 Assigned To: mysql Block user comment: N Private report: N New Comment: Just wondering if anyone has given this any thought recently? It's been absolutely crippling my xdebug usage since upgrading to 5.4.14 a month ago. I'd vote for including it in the next release of 5.4, given that as far as I can tell, most of the world is only just now starting to move from 5.3 to 5.4 as their minimum requirement / standard development version, so punting this till 5.5 is going to mean a long time for us work-a-day application developers having to deal with page upon page upon page of "can't fetch result" and "property access" warnings on xdebug sessions. Or at the very least, make it a notice instead of a warning. My $0.02. Previous Comments: ------------------------------------------------------------------------ [2013-01-30 12:56:09] dev at pp3345 dot net Hello, I've also experienced this bug in the past, using reflection on a freed resource. Are there any news on when the bug fix will be included in PHP? I think it wouldn't be a problem to include it in the next PHP 5.4/5.3 release since a ton of warnings isn't intended behavior. At least it should be in PHP 5.5. ------------------------------------------------------------------------ [2012-11-23 10:20:17] u...@php.net Thanks for the patch. It seems straight forward , however, it changes behaviour in case of user errors. This makes me wonder in which PHP version it should go. Current behaviour: a) var_dump() - the XDebug view res->free(); var_dump(res) <-- throws a ton of warnings b) Invalid property access - user error: why access free'd resource? res->free(); var_dump(res->lengths) <--- throws a ton of warnings c) Invalid method access - user error: why access free'd resource? res->free(); res->free(); <--- trows a ton of warnings In all three cases the user is confronted with warnings that he could ignore, if he wanted. The patch leaves the user with: a) var_dump() - the XDebug view res->free() var_dump(res) <-- Warning on accessing free'd resource is gone b) res->free(); var_dump(res->lengths) <-- Notice var_dump(res) <-- Warning gone In sum: user gets less hints about his, well, "why are you doing that"-code. c) res->free(); res->free(); <-- Fatal Application that used to work now throws fatal Please, note that I am not saying no to fixing the var_dump() issue. Trying to explain the side effects of the proposed patch and asking what PHP version would qualify for such a change. ------------------------------------------------------------------------ [2012-11-15 17:17:16] u...@php.net Derick, thanks a lot for the patch. All three of us MySQL guys are at a team meeting. We will fly back home tomorrow morning. We can have a look once home and no more tired (flight goes at 6:xx am). ------------------------------------------------------------------------ [2012-11-11 12:53:01] der...@php.net The following patch has been added/updated: Patch Name: mysqli-clear-result-cleanup Revision: 1352638381 URL: https://bugs.php.net/patch-display.php?bug=63486&patch=mysqli-clear-result-cleanup&revision=1352638381 ------------------------------------------------------------------------ [2012-11-11 12:52:02] der...@php.net Description: ------------ An Xdebug user filed the following report: http://bugs.xdebug.org/view.php?id=900 I've just investigated this, and found out that this is something I can't fix in Xdebug. mysqli_free_result() destroys the internal object, but leaves the resource (in your case, $rs) in a silly state. All Xdebug does internally is basically a var_dump( $rs ), and after it is freed with mysqli_free_result(), that throws exactly the same error (without Xdebug). This can however, easily be fixed in the MySQLi extension with the attached patch. The patch applies to PHP 5.4, but this also a problem in master and PHP 5.3. It is also possible, that other mysqli_free_* functions can benefit from a similar construct. Test script: --------------- <?php $con = mysqli_init(); mysqli_real_connect($con, '127.0.0.1', 'root', 'xxxxx'); $rs = mysqli_query($con, 'show schemas'); $row = mysqli_fetch_object($rs); mysqli_free_result($rs); echo "hi mom"; var_dump( $rs ); ?> Expected result: ---------------- The expected result is perhaps something like "NULL" (which my patch makes it do). Actual result: -------------- hi mom Warning: var_dump(): Couldn't fetch mysqli_result in /home/derick/dev/php/derickr-xdebug/tests/bug00900.php on line 10 Call Stack: 0.0002 662616 1. {main}() /home/derick/dev/php/derickr-xdebug/tests/bug00900.php:0 0.0032 672792 2. var_dump(class mysqli_result { public $current_field = NULL; public $field_count = NULL; public $lengths = NULL; public $num_rows = NULL; public $type = NULL }) /home/derick/dev/php/derickr-xdebug/tests/bug00900.php:10 Warning: var_dump(): Couldn't fetch mysqli_result in /home/derick/dev/php/derickr-xdebug/tests/bug00900.php on line 10 Call Stack: 0.0002 662616 1. {main}() /home/derick/dev/php/derickr-xdebug/tests/bug00900.php:0 0.0032 672792 2. var_dump(class mysqli_result { public $current_field = NULL; public $field_count = NULL; public $lengths = NULL; public $num_rows = NULL; public $type = NULL }) /home/derick/dev/php/derickr-xdebug/tests/bug00900.php:10 Warning: var_dump(): Property access is not allowed yet in /home/derick/dev/php/derickr-xdebug/tests/bug00900.php on line 10 Call Stack: 0.0002 662616 1. {main}() /home/derick/dev/php/derickr-xdebug/tests/bug00900.php:0 0.0032 672792 2. var_dump(class mysqli_result { public $current_field = NULL; public $field_count = NULL; public $lengths = NULL; public $num_rows = NULL; public $type = NULL }) /home/derick/dev/php/derickr-xdebug/tests/bug00900.php:10 Warning: var_dump(): Couldn't fetch mysqli_result in /home/derick/dev/php/derickr-xdebug/tests/bug00900.php on line 10 Call Stack: 0.0002 662616 1. {main}() /home/derick/dev/php/derickr-xdebug/tests/bug00900.php:0 0.0032 672792 2. var_dump(class mysqli_result { public $current_field = NULL; public $field_count = NULL; public $lengths = NULL; public $num_rows = NULL; public $type = NULL }) /home/derick/dev/php/derickr-xdebug/tests/bug00900.php:10 Warning: var_dump(): Property access is not allowed yet in /home/derick/dev/php/derickr-xdebug/tests/bug00900.php on line 10 Call Stack: 0.0002 662616 1. {main}() /home/derick/dev/php/derickr-xdebug/tests/bug00900.php:0 0.0032 672792 2. var_dump(class mysqli_result { public $current_field = NULL; public $field_count = NULL; public $lengths = NULL; public $num_rows = NULL; public $type = NULL }) /home/derick/dev/php/derickr-xdebug/tests/bug00900.php:10 class mysqli_result#2 (5) { public $current_field => NULL public $field_count => NULL public $lengths => NULL public $num_rows => NULL public $type => NULL } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=63486&edit=1