Hi!
PHP is really nifty in the way you can instantiate classes by using string variables like so:
That way you can create flows where classes that are used in the same way can use the same code even if you don't know which class will use the code beforehand.
My question is whether there is a way to do this for static methods of a class.
so something like:
The above example would of course get all users but it does not work for obvious reasons. Does anyone know a way to accomplish what I'm asking?
best regards
Rythmic
PHP is really nifty in the way you can instantiate classes by using string variables like so:
Code:
$str_class_name = 'User'; $instance = new $str_class_name();
My question is whether there is a way to do this for static methods of a class.
so something like:
Code:
class User {
public static function get_all(){
return "calling get_all from user";
}
}
$class_name = 'User';
$class_name::get_all();
best regards
Rythmic
Comment