|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-12-23 13:56 UTC] joelp at email dot cz
Description:
------------
If I try to use ReflectionMethod::InvokeArgs after using function array_unshift inside of user function, this return me this:
Warning: Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, value given in /www/transaction_test.php on line 132
Fatal error: Uncaught exception 'ReflectionException' with message 'Invocation of method mysqli_stmt::bind_param() failed' in /www/transaction_test.php:132 Stack trace: #0 /www/transaction_test.php(132): ReflectionMethod->invokeArgs(Object(mysqli_stmt), Array) #1 /www/transaction_test.php(146): test_case_function('INSERT INTO `te...', Array, 'ss') #2 {main} thrown in /www/transaction_test.php on line 132
If I try run it out of user function. Everything is OK.
Test script:
---------------
function test_case_function ($sql,$variables,$vars) {
$mysqli = new mysqli(db_server, db_user_name, db_user_passwd, db_name);
$mysqli->query("SET NAMES 'utf8'") or die ('Could not set Charset');
$mysqli->autocommit(FALSE);
array_unshift($variables,$vars);
if ($stm=$mysqli->prepare($sql)) {
$method= new ReflectionMethod('mysqli_stmt','bind_param');
$method->invokeArgs($stm,$variables);
}
$stm->execute();
printf("%d Row inserted\n", $stm->affected_rows);
$mysqli->commit();
$stm->close();
$mysqli->close();
}
$sql = "INSERT INTO `test_table` (`time`,`one`,`two`) VALUES (NOW(),?,?);";
$vars = 'ss';
$variables = array ("one62","two62");
test_case_function($sql,$variables,$vars);
Expected result:
----------------
Script print "1 Row inserted "
Actual result:
--------------
Warning: Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, value given in /www/transaction_test.php on line 132
Fatal error: Uncaught exception 'ReflectionException' with message 'Invocation of method mysqli_stmt::bind_param() failed' in /www/transaction_test.php:132 Stack trace: #0 /www/transaction_test.php(132): ReflectionMethod->invokeArgs(Object(mysqli_stmt), Array) #1 /www/transaction_test.php(146): test_case_function('INSERT INTO `te...', Array, 'ss') #2 {main} thrown in /www/transaction_test.php on line 132
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 12 10:00:01 2025 UTC |
This is not a bug but a problem how you pass the arguments. As the warning says, you need to give a variable, but you give values: $variables = array ("one62","two62"); Instead give variables: $var1 = "one62"; $var2 = "two62"; $variables = array (&$var1, &$var2); Hope this is helpful.