Answer the question
In order to leave comments, you need to log in
How else can you substitute a method call?
$res = $this->$method['name']($parser_name);
Question 1 I came across this code, is it normal from the point of view of OOP?
serginhold fully answered this question. I knew that the code for substituting the method, but I thought why do it, it turns out you don’t need to do it
$method = 'getName';
$obj->$method(); // $obj->getName();
$method = 'getTitle';
$obj->$method(); // $obj->getTitle();
$this->{$method['name']}($parser_name);
//можно и через рефлексию:
$reflectionMethod = new ReflectionMethod($this, $method['name']);
$reflectionMethod->invoke($this, $parser_name);
Answer the question
In order to leave comments, you need to log in
nothing, usually it looks like shit code, because situations where this is needed are extremely rare
sense in passing the name of a method or property through a variable, and that's it. Type in one case such a method, in another another
$method = 'getName';
$obj->$method(); // $obj->getName();
$method = 'getTitle';
$obj->$method(); // $obj->getTitle();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question