Reputation: 801
My variable $column
returns project
.
I would like to run the method getProject()
dynamically.
This is what I have tried:
$column = ucfirst($column);
$typeOfTask->get{$column}();
But i get this error:
Notice: Undefined property: App\Entity\TypeOfTask::$get
How can I fix this?
Upvotes: 0
Views: 181
Reputation: 1318
In that particular case you can simply use:
$methodName = 'get' . ucfirst($column);
$typeOfTask->$methodName();
In this case if $column == 'project'
then it will call method getProject
on object $typeOfTask
.
Upvotes: 1