Bug #60601 [Opn->Nab]: ReflectionMethod::InvokeArgs not work normally in function
| From: | johannes@php.net | Date: | Sat, 11 Feb 2012 00:33:27 +0000 |
| Subject: | Bug #60601 [Opn->Nab]: ReflectionMethod::InvokeArgs not work normally in function | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-167416@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60601&edit=1
ID: 60601
Updated by: johannes@php.net
Reported by: joelp at email dot cz
Summary: ReflectionMethod::InvokeArgs not work normally in
function
-Status: Open
+Status: Not a bug
Type: Bug
Package: Arrays related
Operating System: Linux
PHP Version: 5.3.8
Block user comment: N
Private report: N
New Comment:
as the error message says mysqli_stmt::bind_param() expects references. When called in this indirect
way there is nothing which can be used as a reference.
Previous Comments:
------------------------------------------------------------------------
[2012-01-05 08:58:23] joelp at email dot cz
Yes this works. But that not solved, why this code work correctly outside of the function and not
works inside.
------------------------------------------------------------------------
[2011-12-29 01:11:31] hanskrentel at yahoo dot de
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.
------------------------------------------------------------------------
[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