Search code examples
phpphpstormsignature

mysqli_stmt_init is throwing a warning in PhpStorm


I'm trying to understand whether I did something wrong with a mysqli_stmt_init method.

Everything is working but PhpStorm keeps showing Method call uses 1 parameters, but method signature uses 0 parameters. What does that mean?

I have triple checked everything and googled for quite some time with no results on why PhpStorm is throwing this warning.

function mysqliConnect(){
    $connect = mysqli_connect(dbhost,dbuser,dbpass,dbname);
    if (mysqli_connect_errno()) {
        echo `Failed to connect to MySql with erro: ` . mysqli_connect_error();
    }
    mysqli_set_charset($connect, 'utf8mb4');
    return $connect;
}

    $connect = mysqliConnect();
    $uid = mysqli_real_escape_string($connect, $uid);

    $query = "SELECT * FROM `user` WHERE uid = ?";
    $stmt = mysqli_stmt_init($connect); // <-- WARNING
    if (!mysqli_stmt_prepare($stmt, $query)) {
        echo 'SQL Error';
    } else {
        mysqli_stmt_bind_param($stmt, 'i',$uid);
        mysqli_stmt_execute($stmt);
        $result = mysqli_stmt_get_result($stmt);
    }

Solution

  • If you CTRL + click on the mysqli_stmt_init() function you will see the embedded stubs that JetBrains uses for intellisense.

    /**
     * Initializes a statement and returns an object for use with mysqli_stmt_prepare
     * @link http://fr2.php.net/manual/en/mysqli.stmt-init.php
     * @return mysqli_stmt
     */
    function mysqli_stmt_init () {}
    

    These only have an implementation without parameters (the one used by the object oriented version) and not the procedural version which takes a single mysqli argument.

    This is obviously a bug, but the way Jetbrains Intellisense works (with embedded stubs) makes it very difficult to solve, because the same method cannot have multiple implementations with different method signatures in the stub files.