Bug #63486 [Com]: mysqli_free_result leave the resource variable in a messy state

From: Date: Tue, 03 Mar 2015 08:08:37 +0000
Subject: Bug #63486 [Com]: mysqli_free_result leave the resource variable in a messy state
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191073@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63486&edit=1

 ID:                 63486
 Comment by:         hans dot puac at gmail dot com
 Reported by:        derick@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:

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.


Previous Comments:
------------------------------------------------------------------------
[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 :-)

------------------------------------------------------------------------
[2014-02-28 08:20:07] hugh dot messenger at gmail dot com

Pretty please can someone take a look at this?  It's still making it almost impossible to
xdebug anything that involves MySQLi.

------------------------------------------------------------------------


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


Thread (24 messages)

« previous php.bugs (#191073) next »