NYCPHP Meetup

NYPHP.org

[nycphp-talk] Callback syntax

Ben Sgro ben at projectskyline.com
Wed Dec 12 13:32:30 EST 2007


Hello ,

I'm trying to do the following:


object calling code:

$callbackSet = array( " " => "return",
                               "w" => "moveUp");

$key = $object->nonBlockOnInput( );

$object->process($key, $callbackSet);


.... inside the class....

public function process($callbackSet)
{
            reset($optionSet);
        while(list($index, $callbackFunction) = each($optionSet))
        {
            switch ($key)
            {
                case $index:
                    call_user_func($this->$callbackFunction);
                break;
            }
        }
}


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( ).

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

Any ideas?

- Ben



More information about the talk mailing list