php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17246 failed in passing by reference
Submitted: 2002-05-15 08:13 UTC Modified: 2002-10-24 16:18 UTC
From: kubo at isite dot co dot jp Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.2.0 OS: Solaris 8
Private report: No CVE-ID: None
 [2002-05-15 08:13 UTC] kubo at isite dot co dot jp
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
?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-05-15 08:27 UTC] kubo at isite dot co dot jp
Sorry, output is wrong.
following right output:
case 1:
$a = 1
$b = 2
case 2:
$a = 1
$b = 2
case 3:
$a = foo
$b = bar
case 4:
$a = 1st
$b = 2nd
case 5:
$a = 1
$b = 2
case 6:
$a = 1st
$b = 2nd

Regards,

KUBO Atsuhiro
 [2002-10-24 16:18 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The sample code works, if it does not you may need to enable
'allow_call_time_pass_reference' option.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 03:01:27 2024 UTC