I have a class that handles AJAX requests for my plugin. The class has a __callStatic wrapper for all actions, which subsequently calls non-static methods for each action, like so:
class TP_AJAX_wrapper {
public static function __callStatic( $name, $args = null ) {
check_ajax_referer( 'tp_ajax_nonce' );
$out = array();
try {
$res = call_user_func( array( __CLASS__, $name ) );
} catch(Exception $e) {
$out['error'] = $e->getMessage();
}
$out['responseStatus'] = $res ? 'ok' : 'null';
$out['response'] = $res;
echo json_encode($out);
die();
}
protected static function someAction() {
return array( 'someValue' => 3 );
}
}
Then I have an array of actions which I initialize using:
foreach ( $ajax_actions as $action ) {
add_action ( 'wp_ajax_tp_'.$action, array( 'TP_AJAX_wrapper', $action ) );
}
This works great for PHP 5.3+, but fails miserably on older versions.
Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'TP_AJAX_wrapper::someAction' was given in /path/to/wordpress/wp-includes/plugin.php on line 395
Since it's written in a plugin, used on all sorts of hosts, some of which support PHP 5.3, others which don't, I have to make it a little more flexible. What I can't figure out is a way to emulate __callStatic (introduced in 5.3) for older versions of PHP.
What I'm looking for is a way to emulate the __callStatic wrapper for older versions. I've tried using __call as well, which is supposed to handle static method calls if the first argument is a classname, rather than an object, but I keep getting the same error.
Halp?