php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24631 call_user_func (and call_user_func_array) disrespect returned references
Submitted: 2003-07-12 21:46 UTC Modified: 2003-07-12 22:10 UTC
From: matthewb at syrah dot us Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.3.2 OS: FreeBSD
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: matthewb at syrah dot us
New email:
PHP Version: OS:

 

 [2003-07-12 21:46 UTC] matthewb at syrah dot us
Description:
------------
call_user_func and call_user_func do respect functions that return references.  That is, function foo that returns a references to an object, does not return a reference to an object when foo is called via call_user_func.  Instead, foo called via call_user_func returns a "copy" of the object.  (I'm not sure "copy" is the right word.)  See the code example for a concise example of the problem.

Note: this may cease to be a problem in PHP5, as it is my understanding that objects will be passed/returned by reference by default.

If my you do not understand my description and my reproduce code, email me and I will happily explain it to you.

Many thanks.

Reproduce code:
---------------
<?php

$x->var = 1;

function & foo (&$x) {
  return $x; }

$y =& foo ($x);
print "y->var = ". $y->var. "    <br>\n";
$x->var++;
print "y->var = ". $y->var. "    <br>\n";

$z =& call_user_func ("foo", &$x);
print "z->var = ". $z->var. "    <br>\n";
$x->var++;
print "z->var = ". $z->var. "    <br>\n";

$w =& call_user_func_array ("foo", array (&$x));
print "w->var = ". $w->var. "    <br>\n";
$x->var++;
print "w->var = ". $w->var. "    <br>\n";

?>


Expected result:
----------------
y->var = 1    <br>
y->var = 2    <br>
z->var = 2    <br>
z->var = 3    <br>
w->var = 3    <br>
w->var = 4    <br>

Note that I expect z->var and w->var to get inceremented just as y->var gets inceremented.

Actual result:
--------------
y->var = 1    <br>
y->var = 2    <br>
z->var = 2    <br>
z->var = 2    <br>
w->var = 3    <br>
w->var = 3    <br>

Note that in reality, however, z->var and w-> did not get inceremented.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-12 22:10 UTC] sniper@php.net
Fixed in ZE2 (PHP5).

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Sep 19 15:01:27 2024 UTC