NYCPHP Meetup

NYPHP.org

[nycphp-talk] Callback syntax

Scott Mattocks scott at crisscott.com
Wed Dec 12 13:50:10 EST 2007


Ben Sgro wrote:
> It doesn't seem to work.  I'm not sure of the syntax to do this. moveUp( 
> ) is a method of the class,
> but I'm not sure how to tell it, call_user_func( ), since I need the 
> syntax to be $this->functionName( ).

If you are trying to call a method of an object or class you need to 
tell PHP which object or class to call. You do this by passing the 
object or class as the first element of the callback array.

call_user_func(array($this, $callbackFunction));

or for static methods:

call_user_func(array(__CLASS__, $callbackFunction));

> 
> Also, I need to be able to call return as well.

Huh? You want to return the value of the callback? Just return the value 
of call_user_func().

-- 
Scott Mattocks
Author: Pro PHP-GTK
http://www.crisscott.com



More information about the talk mailing list