Reputation: 25060
I have a class name stored in an object property, and I would like to use it to access a static method from that class, but I can't seem to find a working syntax:
$this->className::staticMethod()
doesn't work and
{$this->className}::staticMethod()
doesnt' work either, does PHP have a correct syntax to do this?
Upvotes: 2
Views: 56
Reputation: 7695
If you have PHP version > 5.2
call_user_func($this->className.'::staticMethod');
else
call_user_func(array($this->className, 'staticMethod'));
Also with arguments:
call_user_func_array(array($this->className, 'staticMethod'), array($argument, $anotherArg));
Upvotes: 2
Reputation: 43479
Try this syntax:
$class = $this->className;
$class::staticMethod();
Upvotes: 2