mysqli + xdebug breakpoint after closing statement result in many warnings

£可爱£侵袭症+ 提交于 2019-12-28 05:49:06

问题


I have a piece of code like this:

$conn = new mysqli($host, $username, $passwd, $dbname);

...

$stmt = $conn->prepare('SELECT ...');
$stmt->bind_param(...);
$stmt->execute();
$stmt->bind_result(...);
while($stmt->fetch())
{
    // do something here
}
$stmt->close();

...

// do something more here that has absolutely nothing to do with $stmt

This works perfectly fine. I get the results I expected, there are no errors or anything that is not supposed to happen.

But if I set a break point (Xdebug 2.2.5 / 2.2.6 / 2.2.8 / 2.3.2 and PHP 5.5.3 / 5.5.15 / 5.6.0 / 5.6.6 / 5.6.10) to a line after $stmt->close();, I get many warnings like

Property access is not allowed yet

or

Couldn't fetch mysqli_stmt

I thought I missed to close another mysqli statement, but I get all results. There seems to be just no problem in my code...

Is there a way to get rid of this wrong warnings?

Update: This problem still exist in PHP 7.0.1 / Xdebug 2.4.0 RC3.


回答1:


There are some similar issues reported
http://bugs.xdebug.org/view.php?id=900
https://bugs.php.net/bug.php?id=60778

One way to get rid of this messages is to add

unset($stmt);

after closing the statement and before the breakpoint. If this does not help, you should also add

unset($connection);

after closing the connection as mentioned by @Martin in the comments.

This does not solve the problem itself, but let you go on with your work until this may be fixed some time.

EDIT: Now there is also a reported issue :)

EDIT: This seems to be a bug in the MySQLi driver as reported here.

EDIT: Looks like this bug does not appear if you use PDO. So this is maybe an other reason to switch to PDO.




回答2:


FWIW, this was a bug in PHP (https://bugs.php.net/bug.php?id=67348&edit=1), which should be fixed for PHP 7.4: https://github.com/php/php-src/commit/579562176b71820ad49d43b2c841642fef12fe57




回答3:


/* PHP 7.0.5 - MYSQLi (mysqlnd 5.0.12-dev)  - XDEBUG 2.4 */
/* This one will allow breakpoints before / after / step through */

if (function_exists('xdebug_disable'))
              {
               $errorlevel=error_reporting();
               $displayerrors=ini_get('display_errors');
               ini_set('display_errors',0);
                error_reporting(0);
                xdebug_disable();
              }

                mysqli_close($DATA_DBH);
               unset($DATA_DBH);
      if (function_exists('xdebug_enable'))
              {
                xdebug_enable();
                error_reporting($errorlevel);
               ini_set('display_errors',$displayerrors);
              }



回答4:


I've been getting a similar error with PHP 7.1.1 / Xdebug 2.5.1 while trying to measure test coverage in the console, without an IDE:

mysqli_init(): Property access is not allowed yet in /home/www/wp-includes/wp-db.php on line 1515

The solution was to comment out all xdebug-related settings in php.ini. It seems in my case they were copy-pasted from an earlier version and caused problems. Without those settings all started working flawlessly.

P.S.: What I had in the config before removal is:

xdebug.auto_trace = 1
xdebug.collect_includes = 1
xdebug.collect_params = 1
xdebug.collect_return = 1
xdebug.default_enable = "On"
xdebug.extended_info = 1
xdebug.idekey = "xdebug"
xdebug.max_nesting_level = 100
xdebug.remote_enable = 1
xdebug.remote_autostart=1
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "127.0.0.1"
xdebug.remote_port = 9000
xdebug.show_local_vars = 9
xdebug.var_display_max_children = 128



回答5:


What Alan wants to state is, that you can use these snippets the following way:

$stmt = $conn->prepare('SELECT ...');
$stmt->bind_param(...);
$stmt->execute();
$stmt->bind_result(...);
while($stmt->fetch())
{
    // do something here
}

// Disable the buggy interconnection between xDebug and PHP/MySQLi for a certain period
if (function_exists('xdebug_disable'))
              {
               $errorlevel=error_reporting();
               $displayerrors=ini_get('display_errors');
               ini_set('display_errors',0);
                error_reporting(0);
                xdebug_disable();
              }

$stmt->close();
unset($stmt);
unset($conn);

// finalle bring back the functionality
if (function_exists('xdebug_enable'))
              {
                xdebug_enable();
                error_reporting($errorlevel);
               ini_set('display_errors',$displayerrors);
              }

For me this also worked in PHP 5.6 And I use it as a workaround in https://github.com/joshcam/PHP-MySQLi-Database-Class

like so in MSQLiDB.php -> _dynamicBindResults():

/* BUG http://stackoverflow.com/questions/25377030/mysqli-xdebug-breakpoint-after-closing-statment-result-in-many-warnings 
           temporarily disable the buggy module interconnection         */
        if (function_exists('xdebug_disable'))
              {
               $errorlevel=error_reporting();
               $displayerrors=ini_get('display_errors');
               ini_set('display_errors',0);
                error_reporting(0);
                xdebug_disable();
              }
        /* Returning to normal xDebugging is only possible after $this->_mysqli->close
        if (function_exists('xdebug_enable'))
              {
                xdebug_enable();
                error_reporting($errorlevel);
               ini_set('display_errors',$displayerrors);
              }
         * 
         */
        $stmt->close();

Please note that I actually cannot reenable the xDebugging immediatly because this library destructs the MySQLi object very late. But that seems to be no reason for the debugger to stop showing debugging information :-> I had no time yet to figure out why.




回答6:


A prolific number of exceptions and warning were spewing out of VSCode for me using PHP 7.2.19 with Xdebug 2.7.2. The unset() approach did not work for me but I managed to stop them with a dummy 'noop' statement as the last line of executed code, e.g.,

function do_mysqli_stuff() {

   ...

   while(false); // noop
}

or you could use assert(true); if this offends your sensibilities.

Anyway I hope this helps someone because the warnings are pretty annoying ;-)

php7 xdebug noop



来源:https://stackoverflow.com/questions/25377030/mysqli-xdebug-breakpoint-after-closing-statement-result-in-many-warnings

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!