php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60601 ReflectionMethod::InvokeArgs not work normally in function
Submitted: 2011-12-23 13:56 UTC Modified: 2012-02-11 00:33 UTC
From: joelp at email dot cz Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.3.8 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: joelp at email dot cz
New email:
PHP Version: OS:

 

 [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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-29 01:11 UTC] 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.
 [2012-01-05 08:58 UTC] 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.
 [2012-02-11 00:33 UTC] johannes@php.net
-Status: Open +Status: Not a bug
 [2012-02-11 00:33 UTC] johannes@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 02:01:29 2024 UTC