title: call_user_func_array with references
body: <p>I'm basically trying to call <a href="http://ca2.php.net/manual/en/mysqli-stmt.bind-param.php" rel="nofollow">mysqli::bind_param</a> via <code>call_user_func_array</code>.</p>
  
  <p>Here's my function:</p>
  
  <pre><code>function Insert($table, $values=array(), $flags=0) {
      $field_count = count($values);
  
      if($field_count &gt; 0) {
          $fields = implode(',',array_keys($values));
          $placeholders = implode(',',array_repeat('?',$field_count));
      } else {
          $fields = '';
          $placeholders = '';
      }
  
      if($flags &gt; 0) {
          $flag_arr = array();
          if($flags &amp; self::LOW_PRIORITY) $flag_arr[] = 'LOW_PRIORITY';
          if($flags &amp; self::DELAYED) $flag_arr[] = 'DELAYED';
          if($flags &amp; self::HIGH_PRIORITY) $flag_arr[] = 'HIGH_PRIORITY';
          if($flags &amp; self::IGNORE) $flag_arr[] = 'IGNORE';
          $flags_str = implode(' ',$flag_arr);
      } else {
          $flags_str = '';
      }
  
      $sql = "INSERT $flags_str INTO $table ($fields) VALUES ($placeholders)";
      $stmt = $this-&gt;mysqli-&gt;prepare($sql);
      if($stmt === false) {
          throw new Exception('Error preparing MySQL statement.&lt;br/&gt;MSG: '.$this-&gt;mysqli-&gt;error.'&lt;br/&gt;SQL: '.$sql);
      }
  
      if($field_count &gt; 0) {
          $types = '';
          foreach($values as $val) {
              if(is_int($val)) $types .= 'i';
              elseif(is_float($val)) $types .= 'd';
              elseif(is_string($val)) $types .= 's';
              else $types .= 'b';
          }
          $params = array_merge(array($types),array_values($values));
          call_user_func_array(array($stmt,'bind_param'),$params);
      }
  
      $stmt-&gt;execute();
      return $stmt;
  }
  </code></pre>
  
  <p>The problem occurs on the <code>call_user_func_array</code> line. I get this error:</p>
  
  <blockquote>
    <p>Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, value given</p>
  </blockquote>
  
  <p>I understand the problem, I'm just not sure how to work around it.</p>
  
  <p>As an example, the function may be called like this:</p>
  
  <pre><code>$db-&gt;Insert('pictures',array('views'=&gt;1));
  </code></pre>
  
  <p>And <code>var_dump($params)</code> would yield this:</p>
  
  <pre><code>array
    0 =&gt; string 'i' (length=1)
    1 =&gt; int 1
  </code></pre>
  
  <p>So, is there a way to call <code>mysqli::bind_param</code> with a variable number of arguments, or somehow make my array into references?</p>