Viewed   59 times

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.



You are passing an array of elements ($passArray). The second item inside the passed array needs to be a reference, since that is really the list of items you are passing to the function.

Tuesday, October 11, 2022

I'm not really an expert in PHP but from my experience passing by value is better. This way code won't have side effects and that mean it will be easier to understand and maintain and do all sorts of crazy things on it, like using it as callback for map function. So I'm all for parse_b way of doing things.

Wednesday, October 12, 2022

The constants are not part of the object so using $mysqli::CONSTSANT or $mysqli->CONSTANT won't work that way.

Here's the beginning of an example. You'll have to look at the rest of the MySQLi constants and finish the switch statement. The ones that aren't included will remain strings.

$result = $mysqli->query('SELECT * FROM `accounts`');
$fields = $result->fetch_fields();

// Loop through each row.
while ( $row = $result->fetch_row() )
  // Loop through each field.
  foreach ( $row as $key => &$value )
    // Using the $key, find the type of the current field.
    switch ( $fields[$key]->type )
      // Convert INT to an integer.
      case MYSQLI_TYPE_TINY:
      case MYSQLI_TYPE_LONG:
      case MYSQLI_TYPE_INT24:
        $value = intval($value);

      // Convert FLOAT to a float.
        $value = floatval($value);

      // Convert TIMESTAMP to a DateTime object.
      case MYSQLI_TYPE_DATE:
        $value = new DateTime($value);


Tuesday, September 20, 2022

A bit sloppy, but gets the job done.

function refValues($arr){
    if (strnatcmp(phpversion(),'5.3') >= 0) //Reference is required for PHP 5.3+
        $refs = array();
        foreach($arr as $key => $value)
            $refs[$key] = &$arr[$key];
        return $refs;
    return $arr;

$params = array();

$query = "SELECT * FROM table WHERE status = 1";

// Iterate over your paramters from $_GET
foreach ($_GET as $k => $v) 
    $query .= " AND $k = ?";
    $params[$k] = helper::sanitize($v);
// After you get through all your params...

$stmt = $mysqli->prepare($query);

// Bind em.
call_user_func_array(array($stmt, 'bind_param'), refValues($params));

That should do it, though I've never bound with mysqli before. Let me know how that works.

Saturday, December 10, 2022

As answered by Ernest Friedman-Hill at link text

The root of problem was the fact that RMI doesn't support pass by reference , so making the message class serializable and creating the remote instance of ServerServices in that serializable class can make this application work


creating the remote instance of Message class in client class and publishing that from RMI registry can also work.

In this code the local references were used instead of remote, so it was getting the 0 elements in the list from Serverservices class.

thanks again to: Ernest Friedman-Hill.

Thursday, October 13, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :