Advantages and disadvantages of each option work with the object?

What are the pluses and minuses of each option?

First
$widgets = new Widgets();
$widgets->headMenu();


Second
$widgetHeadMenu = (new Widgets)->headMenu();

Third
call_user_func([new Widgets, "headMenu" ] );
July 9th 19 at 13:55
1 answer
July 9th 19 at 13:57
Solution
The first and second options are essentially synonyms, but only the second is shorthand for the first. It can be used if you do not want to pass parameters to the constructor of the class. If necessary, it is better to use the same first, for reasons of readability of the code. The difference in performance between them is negligible.

The third option is not in order to call objects. It is in 95% of cases do not require the developer, also in this case, once the function is called. To develop frameworks \ CMS he is more than useful because it allows to handle variables with names of objects, classes, etc.
> only the second is shorthand for the first. It can be used if you do not want to pass parameters to the constructor of the class.

Option 2 can also pass parameters to the constructor. There is more business in the pass variable with a reference to the object itself and a short recording. - gay_Lang commented on July 9th 19 at 14:00

Find more questions by tags OOPPHP