Let's say I can call a method like this: core::get()
. What is the best way to reference to this method? Everytime I call a function called get
it should call core::get()
and pass the same parameters.
All I could come up with was this:
function get(){
call_user_func_array('core::get', func_get_args());
}
But it doesn't look very elegant if I compare it to the way I'd solve this in JavaScript:
var get = core.get;
I'm sure I missed something in PHP, so does anybody has a better solution for this?
This is almost equivalent to your solution that already looks good:
$get = function () {
call_user_func_array('core::get', func_get_args());
};
//usage
$get('arg1','arg2');
Note in the case you got a simple function you have could do this:
function foo() {}
$var = 'foo';
$var(); //> same as calling foo();