ID: 9054
Updated by: sterling
Reported By: [EMAIL PROTECTED]
Status: Open
Bug Type: Class/Object related
Operating System: Linux/Solaris
PHP Version: 4.0.4pl1
New Comment:

you must pass a reference, anyhoo, call_user_method() is
deprecated, use call_user_function(array(&$obj, "Meethod"));
syntax...

Previous Comments:
------------------------------------------------------------------------

[2001-02-01 12:17:02] [EMAIL PROTECTED]

call_user_method doesn't seem to allow the called method to modify it's own viriables 
and what not. It's as though it's copying an object instead of referencing the one 
specified. 

This is the same bug reported in Bug #6347. There weren't any additionally open bugs, 
but I'm using 4.0.4pl1 and I do not see a working solution yet. 

The original script follows. I modified it for a command line implementation (took out 
all the HTML):

----------- Example 1 ------------
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);


this script should increment $t 6 times. It produces the following output:

Direct calls:
a is now: 1
a is now: 2
a is now: 3


Indirect calls:
a is now: 4
a is now: 4
a is now: 4



I also wrote a script to do something similar, and it follows. I call 
"call_user_method" both within the class (using $this) and outside the class.

----------------- Example 2 -------------
class MyClass {
   var $my_Var = "";

   function MyClass ($value = "") {
      $this->my_Var = $value;
      print("my_Var set to " . $this->my_Var . "\n");
   }

   function change ($value = "") {
      print("changing to " . $value . "\n");
      call_user_method("MyClass", &$this, "2");
   }

   function show () {
      print("my_Var is " . $this->my_Var . "\n");
   }
}

$mine = new MyClass("1");
$mine->show();
$mine->change("2");
$mine->show();
call_user_method("MyClass", $mine, "3");
$mine->show();

This should produce the following output:

my_Var set to 1
my_Var is 1
changing to 2
my_Var set to 2
my_Var is 2
my_Var set to 3
my_Var is 3


However it produces this:

my_Var set to 1
my_Var is 1
changing to 2
my_Var set to 2
my_Var is 1
my_Var set to 3
my_Var is 1


------------------------------------------------------------------------



Edit this bug report at http://bugs.php.net/?id=9054&edit=1


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to