mysqli + xdebug breakpoint after closing statement result in many warnings

前端 未结 6 2051
生来不讨喜
生来不讨喜 2020-11-30 07:24

I have a piece of code like this:

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

...

$stmt = $conn->prepare(\'SELECT ...\');
$stmt->bind_par         


        
相关标签:
6条回答
  • 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
    
    0 讨论(0)
  • 2020-11-30 08:06

    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.

    0 讨论(0)
  • 2020-11-30 08:08

    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

    0 讨论(0)
  • 2020-11-30 08:10

    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

    0 讨论(0)
  • 2020-11-30 08:11
    /* 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);
                  }
    
    0 讨论(0)
  • 2020-11-30 08:14

    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.

    0 讨论(0)
提交回复
热议问题