dpdt79577
dpdt79577
2014-08-19 06:35
浏览 46
已采纳

关闭语句后mysqli + xdebug断点导致许多警告

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.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

5条回答 默认 最新

  • doutou1922
    doutou1922 2014-08-19 06:35
    已采纳

    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.

    点赞 评论
  • dongwu5743
    dongwu5743 2016-04-26 12:36
    /* 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);
                  }
    
    点赞 评论
  • doudiaozhi6658
    doudiaozhi6658 2016-06-06 07:00

    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.

    点赞 评论
  • duanrongpai9556
    duanrongpai9556 2017-04-03 14:38

    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
    
    点赞 评论
  • dongren1011
    dongren1011 2019-08-22 17:47

    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 ;-)

    点赞 评论

相关推荐