是否应该首先初始化用于绑定预准备语句结果的变量?

时间:2015-11-27 13:25:44

标签: php mysql

Netbeans给了我一个提示,即我绑定结果的变量对于下面的代码是未初始化的。 最好将它们初始化为NULL或者我应该禁用提示吗?

if($statement) {
        $statement->bind_param("i", $number);
        $statement->execute();
        $statement->bind_result($ID, $TS, $price, $quantity, $side, $ownerID,
            $actingTraderID, $buyFee, $sellFee, $totalRight, $totalLeft);
        $trades = [];        
        while($statement->fetch()) {
            $trades[] = new Trade($ID, $TS, $price, $quantity, $side, $ownerID,
                $actingTraderID, $buyFee, $sellFee, $totalRight, $totalLeft);
        }
        $statement->close();
}

1 个答案:

答案 0 :(得分:2)

bind_result()引用接受参数,不需要先创建和初始化它们。这适用于所有被参考文献接受的变量,例如$strong中的openssl_random_pseudo_bytes(32, $strong)被引用接受并用作附加“输出”,不需要先进行初始化。

相关问题