Edit report at https://bugs.php.net/bug.php?id=63486&edit=1
ID: 63486
Updated by: stas@php.net
Reported by: derick@php.net
Summary: mysqli_free_result leave the resource variable in a
messy state
-Status: Verified
+Status: Closed
Type: Bug
Package: MySQLi related
PHP Version: 5.4.8
Assigned To: mysql
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of jpauli
Revision: http://git.php.net/?p=php-src.git;a=commit;h=f4c96ffcb565c1daa76aa58256e4df6f111f8803
Log: Fix #63486
Previous Comments:
------------------------------------------------------------------------
[2015-03-03 08:08:35] hans dot puac at gmail dot com
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.
------------------------------------------------------------------------
[2015-02-23 13:00:07] ghostaldev at gmail dot com
Can anyone confirm whether or not hans dot puac's workaround is effective?
I seem to be having the same issue when debugging PHP 5.5 on Ubuntu (5.5.9-1ubuntu4.5) with xDebug,
but assigning null to the result object variable after calling free() on it doesn't seem to
solve the problem.
The only obvious difference I can see is that I'm using the object-oriented style.
test.php
--------
<?php
$connection = new mysqli(SOME_HOST, SOME_USER, SOME_PASSWORD, SOME_DATABASE);
$query = 'SELECT some_column FROM some_table';
$q = $connection->query($query, MYSQLI_STORE_RESULT);
$return = $q->fetch_assoc();
$row_count = $q->num_rows;
$q->free();
$q = null;
var_dump($q);
exit;
Output
------
Warning: main(): Couldn't fetch mysqli_result in /vagrant/test/test.php on line 9
Warning: main(): Couldn't fetch mysqli_result in /vagrant/test/test.php on line 9
Warning: main(): Property access is not allowed yet in /vagrant/test/test.php on line 9
Warning: main(): Couldn't fetch mysqli_result in /vagrant/test/test.php on line 9
Warning: main(): Property access is not allowed yet in /vagrant/test/test.php on line 9
Warning: main(): Couldn't fetch mysqli_result in /vagrant/test/test.php on line 9
Warning: main(): Couldn't fetch mysqli_result in /vagrant/test/test.php on line 9
Warning: main(): Property access is not allowed yet in /vagrant/test/test.php on line 9
Warning: main(): Couldn't fetch mysqli_result in /vagrant/test/test.php on line 9
Warning: main(): Property access is not allowed yet in /vagrant/test/test.php on line 9
null
------------------------------------------------------------------------
[2015-02-21 09:57:16] derick@php.net
Ulf said that more than two years ago, and nothing has happened since. I'll be merging this
into 7 unless somebody beats me.
------------------------------------------------------------------------
[2015-02-20 12:43:21] jpauli@php.net
For me, Derick's patch is all right to get merged against 5.5
I PR'ed it at https://github.com/php/php-src/pull/1104
Like ulf says, it will break bad codes reusing the mysqli resource as an object (because we now NULL
it, so it's not an object anymore), but the mysqli resource was anyway in a bad state, so for
me this is clearly a fix that could get merged.
------------------------------------------------------------------------
[2015-01-16 08:57:49] hans dot puac at gmail dot com
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 :-)
------------------------------------------------------------------------
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
https://bugs.php.net/bug.php?id=63486
--
Edit this bug report at https://bugs.php.net/bug.php?id=63486&edit=1