|
Posted by Colin Fine on 10/09/06 22:14
Kimmo Laine wrote:
> I tried to use a class member function as a callback in
> preg_replace_callback, but failed. It announces: " Warning:
> preg_replace_callback() [function.preg-replace-callback]: requires argument
> 2, 'myclass::myfunction', to be a valid callback in ..."
>
> I tried both myclass::myfunction and $this->myfunction, neither worked. Is
> there really no way of using a class member as a callback, it has to be an
> external function? That sucks... :(
>
>
>
From
http://uk.php.net/manual/en/language.pseudo-types.php#language.types.callback:
"Some functions like call_user_func() or usort() accept user defined
callback functions as a parameter. Callback functions can not only be
simple functions but also object methods including static class methods.
"A method of an instantiated object is passed as an array containing
an object as the element with index 0 and a method name as the element
with index 1.
"Static class methods can also be passed without instantiating an object
of that class by passing the class name instead of an object as the
element with index 0. "
Colin
Navigation:
[Reply to this message]
|