Issue passing array as argument [to InvokeArg()] in php - var_dump are the same but only one works? -
backstory: creating function handle mysqli , binding data. code in scope of single function. using reflectionclass programmatically invoke mysqli_stmt_bind_param function (as number of arguments vary).
problem: having issue passing array built programmatically ($refarr). when compare var_dump of array (with sample array created directly), 2 arrays identical. invokearg() method runs sample array ($refarr_sample) not $refarr.
here output code shown below:
array(3) { [0]=> string(2) "si" [1]=> string(5) "user1" [2]=> int(0) } - output of refarr
array(3) { [0]=> string(2) "si" [1]=> string(5) "user1" [2]=> int(0) } - output of refarr_sample
$refarr_sample = array("si", "user1", 0); // var_dump equal in type , length var_dump($refarr); var_dump($refarr_sample); $ref = new reflectionclass('mysqli_stmt'); $method = $ref->getmethod("bind_param"); $method->invokeargs($res,$refarr); // doesn't work ????????? //$method->invokeargs($res,$refarr_sample); // works ????????? $res->execute();
i unsure how fix problem (as i've no clue problem is). don't think issue references. once var_dump same thought wouldn't have mattered. did === comparison between 2 arrays came true. @ point lost why isn't working.
i can link complete code (self contained function) if required.
you should note values in passed array must references (as of php 5.3), whereas $refarr
built dynamically.
... //assign references foreach ($refarr $key => $value) { $refarr[$key] =& $refarr[$key]; } $method->invokeargs($res,$refarr); ...
Comments
Post a Comment