Edit report at https://bugs.php.net/bug.php?id=60601&edit=1
ID: 60601 Comment by: hanskrentel at yahoo dot de Reported by: joelp at email dot cz Summary: ReflectionMethod::InvokeArgs not work normally in function Status: Open Type: Bug Package: Arrays related Operating System: Linux PHP Version: 5.3.8 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2011-12-23 13:56:49] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=60601&edit=1