From: [EMAIL PROTECTED]
Operating system: Solaris 8
PHP version: 4.2.0
PHP Bug Type: Scripting Engine problem
Bug description: failed in passing by reference
Hi, I falied in passing by reference using call_user_function().
In case 2 and 5, I expect that $a and $b are overwritten by MyMethod or
MyFunction. However, they were not overwritten.
Is this right doing? Or is my understanding wrong?
Regards,
KUBO Atsuhiro
test code:
<?php
class MyClass {
function MyMethod(&$arg1, &$arg2) {
$arg1 = 'foo';
$arg2 = 'bar';
}
}
print "case 1:\n";
$a = 1;
$b = 2;
print '$a = ' . $a . "\n";
print '$b = ' . $b . "\n";
print "case 2:\n";
$a = 1;
$b = 2;
$obj = new MyClass;
call_user_func(array(&$obj, 'MyMethod'), $a, $b);
print '$a = ' . $a . "\n";
print '$b = ' . $b . "\n";
print "case 3:\n";
$a = 1;
$b = 2;
call_user_func(array(&$obj, 'MyMethod'), &$a, &$b);
print '$a = ' . $a . "\n";
print '$b = ' . $b . "\n";
print "case 4:\n";
$a = 1;
$b = 2;
MyFunction($a, $b);
print '$a = ' . $a . "\n";
print '$b = ' . $b . "\n";
print "case 5:\n";
$a = 1;
$b = 2;
call_user_func('MyFunction', $a, $b);
print '$a = ' . $a . "\n";
print '$b = ' . $b . "\n";
print "case 6:\n";
$a = 1;
$b = 2;
call_user_func('MyFunction', &$a, &$b);
print '$a = ' . $a . "\n";
print '$b = ' . $b . "\n";
exit();
function MyFunction(&$arg1, &$arg2) {
$arg1 = '1st';
$arg2 = '2nd';
}
?>
output:
$a = 1
$b = 2
case 2:
$a = 1
$b = 2
case 3:
$a = foo
$b = bar
case 4:
$a = hoge
$b = huge
case 5:
$a = 1
$b = 2
case 6:
$a = hoge
$b = huge
?>
--
Edit bug report at http://bugs.php.net/?id=17246&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=17246&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=17246&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=17246&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=17246&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=17246&r=support
Expected behavior: http://bugs.php.net/fix.php?id=17246&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=17246&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=17246&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=17246&r=globals