Doesn't support object context
Opened this issue · 1 comments
While hacking on an existing module, I thought it would be able nice to add an Ajax method to proxy an existing one, For example:
public function getAjax()
{
// Proxy an existing method, maybe used elsewhere, for Ajax.
return $this->getFoo();
}
public function getFoo()
{
// A whole bunch of code normally goes here for stuff written some time ago
return 'foo;
}
But, this doesn't work as we'll get a Fatal error: Using $this when not in object context
due to https://github.com/Joomla-Ajax-Interface/component/blob/master/site/ajax.php#L90.
We could check to see if that method is static, then call it like the following if not:
$helperClass = new $class; $results = call_user_func($helperClass . '->' . $method . 'Ajax');
But, this may have an issue if we don't pass any required parameters when instantiating the class.
Thoughts?
I considered this before when I thought about making my methods non-static in my helper. But ended up not going for it because of the static requirement of the ajax component.
However it's a very valid point about the helper required params. I guess if we were to do it we'd just have to make the assumption there are none. I mean otherwise it's just impossible to achieve the feature.