title: PHP: "... variables can be passed by reference" in str_replace()?
body: <p>I created a function to print a prepared-statement-sql-string with the variables in it, based on what I found in this other <a href="https://stackoverflow.com/questions/962986/how-to-echo-a-mysqli-prepared-statement">StackOverflow question</a>. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>foreach($params as $idx =&gt; $param) {
      if ($idx == 0) continue;
      $sql = str_replace('?', "'" . $param . "'", $sql, 1);
  }
  printError($sql);
  </code></pre>
  
  <p>When I run this I get: <code>Fatal error: Only variables can be passed by reference</code> for line 3. However when i use </p>
  
  <p><code>$sql = preg_replace('/\?/', "'" . $param . "'", $sql, 1);</code> </p>
  
  <p>for line 3 it works fine.</p>
  
  <p>Any idea why? </p>