Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
458 views
in Technique[技术] by (71.8m points)

mysqli - Pass by reference problem with PHP 5.3.1

Ok, this is a weird problem, so please bear with me as I explain.

We upgraded our dev servers from PHP 5.2.5 to 5.3.1.

Loading up our code after the switch, we start getting errors like:

Warning: Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, value given in /home/spot/trunk/system/core/Database.class.php on line 105

the line mentioned (105) is as follows:

call_user_func_array(Array($stmt, 'bind_param'), $passArray);

we changed the line to the following:

call_user_func_array(Array($stmt, 'bind_param'), &$passArray);

at this point (because allow_call_time_pass_reference) is turned off, php throws this:

Deprecated: Call-time pass-by-reference has been deprecated in /home/spot/trunk/system/core/Database.class.php on line 105

After trying to fix this for some time, I broke down and set allow_call_time_pass_reference to on.

That got rid of the Deprecated warning, but now the Warning: Parameter 2 to mysqli_stmt::bind_param() expected to be a reference warning is throwing every time, with or without the referencing.

I have zero clue how to fix this. If the target method was my own, I would just reference the incoming vars in the func declaration, but it's a (relatively) native method (mysqli).

Has anyone experienced this? How can I get around it?

Thank you.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I just experienced this same problem, calling bind_param via call_user_func_array and passing an array of parameters. The solution is to modify the values in the array to be referenced. It's not elegant but it works.

call_user_func_array(array($stmt, 'bind_param'), makeValuesReferenced($passArray));

function makeValuesReferenced($arr){
    $refs = array();
    foreach($arr as $key => $value)
        $refs[$key] = &$arr[$key];
    return $refs;

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...