mikecao/flight — pull request #13 by thybag (2012-07-30 18:59:13+00:00)
Title: Support for calling methods on an object instance.

Hello,

While using your framework I noticed there currently isn't any way to call non-static methods on objects. Since I needed this functionality for a project I was working on, I decided implemented it myself and though I may as well send in a pull request with it :)

My change basically adds a load of extra conditionals in to the invokeMethod in the Dispatcher, which check whether or not $class is an instance and if it is call $class->$method instead of $class::$method.

I'd originally just added a if(is_object($class)) call_user_func_array($func, $params); Although decided to follow your style more closely due to the speed impact of calling call_user_func_array unnecessarily.

Hopefully the code is all okay (and i haven't managed to overlook any obvious ways of doing this already within the framework),
Thanks,
Carl

Example usage:

$obj = new Obj();
Flight::route('/myMethod', array($obj,'myMethod'));