Answer the question
In order to leave comments, you need to log in
How to call a class method using the property value without variables and call_user_func()?
How to call a class method using the property value without variables and call_user_func()?
Class property:
Method call:
private string|null $method
public function match()
{
return match ($this->method) {
'Update', 'Info', 'Remove' => $this->$this->method()
};
}
Fatal error: Uncaught Error: Object of class Class could not be converted to string
$this->$this->method()
does not work, and could not work.
Answer the question
In order to leave comments, you need to log in
Solution (by FanatPHP ):
Documentation: https://www.php.net/manual/en/language.variables.v...
$this->{$this->method}();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question