php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11800 call_user_method() bug (it won't change properties)
Submitted: 2001-06-29 09:02 UTC Modified: 2001-10-21 19:38 UTC
From: bachi2 at insign dot ch Assigned:
Status: Closed Package: Class/Object related
PHP Version: 4.0.6 OS: Linux
Private report: No CVE-ID: None
 [2001-06-29 09:02 UTC] bachi2 at insign dot ch
I've run into this already a year ago and now again: The call_user_method() function does not correctly change the properties of the object it's called upon - OR (what I assume) it copies the called object. Just try the code below - the counter remains on 4, not 6 as supposed. 

(I also tried to pass the obj. by reference: call_user_method ("increase", &$t); - it didn't help)


class test 
{ 
var $a=0; 

function increase() 
{ 
$this->a++; 
echo "a is now: ".$this->a."\n
"; 
} 

} 


$t = new test(); 

echo "Direct calls:\n
"; 
$t->increase(); 
$t->increase(); 
$t->increase(); 

echo "
\n\nIndirect calls:\n
"; 

call_user_method ("increase", $t); 
call_user_method ("increase", $t); 
call_user_method ("increase", $t);


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-10-21 19:36 UTC] sniper@php.net
This is fixed in CVS. 
You just have to use:

call_user_func(array(&$t, "increase"));

instead though.

--Jani

 [2001-10-21 19:38 UTC] sniper@php.net
call_user_method("increase", &$t); works too with PHP 4.1.0RC1 but this function is deprecated.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 17:01:29 2024 UTC