Skip to content

Instantly share code, notes, and snippets.

@GRMule
Created August 10, 2012 16:11
Show Gist options
  • Save GRMule/3315289 to your computer and use it in GitHub Desktop.
Save GRMule/3315289 to your computer and use it in GitHub Desktop.
call_user_func_array doesn't always pass fake references, but when it does, it drinks Dos Equis beer.
<?php
ini_set('display_errors', '1');
error_reporting(E_ALL | E_STRICT);
class testRef {
function test (&$parm1, &$parm2) {
echo '<br>In testRef::test(), param1: '.$parm1;
echo '<br>In testRef::test(), param2: '.$parm2;
}
}
$t = new testRef();
print 'Calling with call_user_func_array: call_user_func_array(array($t, "test"), array("three", "four"))<br>';
print 'Result: ';
call_user_func_array(array($t, "test"), array("three", "four"));
print '<br><br>';
print 'Calling directly: $t->test("value", "value!")<br>';
print 'Result: ';
$t->test("value", "value!");
/* output
Calling with call_user_func_array: call_user_func_array(array($t, "test"), array("three", "four"))
Result:
In testRef::test(), param1: three
In testRef::test(), param2: four
Calling directly: $t->test("value", "value!")
Result: Fatal error: Cannot pass parameter 1 by reference in /usr/web/grcmc/chris/test.php on line 26
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment