|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-11-11 12:52 UTC] derick@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 } Patchesmysqli-clear-result-cleanup (last revision 2012-11-11 12:53 UTC by derick@php.net)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 10:00:01 2025 UTC |
This Problem still exists in different PHP-Versions. I got it in 5.5.9 and 5.6.3 with XAMPP on Windows 7. Please fix this bug! And here a little workaround for all developer who want to use xDebug now. function free_result_fix(&$rs){ $out = mysqli_free_result($rs); $rs = null; return $out; } Replace every mysqli_free_result with the free_result_fix and xDebug will work :-)Hello ghostaldev at gmail dot com, my workaround is working, but not with the object-oriented style. But it seems that something in your query is wrong. (Couldn't fetch mysqli_result) I tried this: $mysqli = new sqlFix('localhost', 'xxx', 'yyy', 'zzz'); $result = $mysqli->query('SELECT * FROM `user`;'); $return = $result->fetch_assoc(); $row_count = $result->num_rows; $result->free(); $result = null; var_dump($result); And in browser I get a NULL from var_dump. But I don´t know if that will help when debugging with Xdebug, because, if you debug this line -> $result->free();, it will crash anyway. My workaround is only so helpful because it´s an own function that I´m not jumping in while debugging.This is fixed at PHP 7.4.9 (cli) (built: Aug 4 2020 11:52:41) ( ZTS Visual C++ 2017 x64 ). Probably fixed at Version 7.4.3. You may check for an int property to see if it's freed: $result->free(); var_dump(isset($result->current_field));//bool(false) var_dump($result);//object(mysqli_result)#3 (0) {}