HNA
HNA

Reputation: 307

Should variables used for binding prepared statement results be initialized first?

Netbeans gives me a hint that the variables I bind the results to are uninitialized for the below code. Is it best to initialize them to something like NULL or should I just disable the hint?

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

Upvotes: 1

Views: 64

Answers (1)

deceze
deceze

Reputation: 522412

The parameters are accepted by reference by bind_result(), there's no need to create and initialise them first. This goes for all variables which are accepted by reference, e.g. the $strong in openssl_random_pseudo_bytes(32, $strong) is accepted by reference and is used as additional "output", it does not need to be initialised first.

Upvotes: 2

Related Questions