I've got some problem.
I want to call static
method of class from another class.
Class name and method are created dynamically.
It's not really hard to do like:
$class = 'className';
$method = 'method';
$data = $class::$method();
BUT, i want to to do it like this
class abc {
static public function action() {
//some code
}
}
class xyz {
protected $method = 'action';
protected $class = 'abc';
public function test(){
$data = $this->class::$this->method();
}
}
And it doesn't work if i don't assign $this->class
to a $class
variable, and $this->method
to a $method
variable.
What's the problem?
$this
always point at the current object - the one that the method is executing in. you can't use$this
and magically have it become some other object's "this". And even if you could do$this->$class->action()
,$class
is just a string. it's not an object, and doesn't point at an instance of an object, so you can't use to execute a method in an object, even if that string is the name of some object. the only thing you could use it for is calling a STATIC method of the class it represents.