Page 1 of 1

method as callback function

Posted: Thu Apr 13, 2006 5:52 pm
by ho.ho
Hello, I want to ask you to help me with this problem:

I want to a callback function for preg_replace_callback. This callback is a class method because it need an access to some object variables.

I've found this solution how to "adress" it:
preg_replace_callback($pattern, array($this,'my_callback'),$string);

works great, but..

I change the instantion (is my english correct???) variable in my_callback:
$this->inst_var++;

while printing some debug info in my_callback, $this->inst_var changes for every pattern convenient in preg_replace_callback.

The problem is, that when i "echo" $this->inst_var after finishing preg_replace_callback, "0" is printed..


Before trying to implement THE SAME in "objects", everything was working good..

I'll be very greatful for any help
Thanks
HoHo

Posted: Thu Apr 13, 2006 8:11 pm
by feyd
I think I'm going to need to see your code to be of any help.

Posted: Thu Apr 13, 2006 9:49 pm
by timvw
(assuming that the object is copied instead of referenced)

Try with

Code: Select all

array(&$this, 'your_callback');

Posted: Fri Apr 14, 2006 1:19 am
by ho.ho
Thank you timvw, that was the problem.
Now it works!!!!!!!!!!!!!