Skip to content

Instantly share code, notes, and snippets.

@asgrim
Last active September 5, 2022 05:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asgrim/22859d7af570c33ee52f34564c24afb2 to your computer and use it in GitHub Desktop.
Save asgrim/22859d7af570c33ee52f34564c24afb2 to your computer and use it in GitHub Desktop.
<?php
$thingsToBind = [
[
'value' => '123',
'param' => 'first',
],
[
'value' => '321',
'param' => 'second',
],
];
foreach ($thingsToBind as $bindParam) {
$value = $bindParam['value'];
/**
* Since `$value` is passed by reference, each iteration the `$value` is overwritten and the previous bind is affected
*
* MUCH WOW
*/
$sth->bindParam($bindParam['param'], $value, $bindParam['type']);
$debugParams[$bindParam['param']] = $value;
}
/**
* In effect, the binds are now:
* first - 321
* second - 321
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment