I found that lot of earlier answers were using simple objectManager for class instantiation in Magento 2.

The results, lot of people are directly using/implementing those answers in their custom implementations.

we should not use the ObjectManager directly!

How can we avoid this practices, so users can be followed best coding standards.

3 Answers 3


The answer is simple. Downvote and explain why the downvote.

  • 1
    I don't think this suitable suggestion because these are old answer in start on m2 . Commented Apr 10, 2017 at 5:39
  • 1
    if they are old answers come back with a better way to do it. But you can still downvote and explain why. I think I have a few answers myself that recommend using OM. I don't mind the downvotes. I now know I was wrong.
    – Marius Mod
    Commented Apr 10, 2017 at 6:13
  • what about answer's using both methods and asking about phtml only solutions? Commented Apr 10, 2017 at 6:16
  • do what you think it's best for those.
    – Marius Mod
    Commented Apr 10, 2017 at 6:21
  • Better: downvote, explain and write a detailed answer on how to use factory methods.
    – Max
    Commented Apr 12, 2017 at 14:34

I seen both link they have both answers with ObjectManager and factory method. So it upto community member what they want to use.For question that don't have factory method you can add answers with factory method with mention don't use object manager because add your reason or add following link.

Important Reminder: One should never call the Object Manager directly


As for most unexperienced users it seems to be a major problem to create modules in Magento2. Most question are directly targeted towards Theme changes, where you can easily use the Object Manager-Solutions.

This doesn't mean that it's a good idea, however it is easy. And thats the matter. You simply cannot tell the users not to show some more option to achieve what OP wants in beforehand, just downvote and explain.

Therefore, in addition to Marius answer, you should always also explain how to create a new module to achieve exactly what OP wants. This includes: Module generation, module enabling, use the Terminal to activate the module and clear the cache, ...

If we do so we can do some parenting here to train unexperienced users to dig deeper into M2's structure and also learn how to code directly. IMHO quality answers will succeed ObjectManager-answers.

Currently most answers are simply: "Extend this or this block, see following template" and thats it. Without Filenames. Without any further explantation. How do you want the users to understand this, if they have literally no experience? Dont forget that Stackexchange is not purely for Pro's, its also a HUGE knowledgebase for absolute beginners everywhere.

Therefore we should encourage our users to write answers in a ELI5-way - just explain every step, they should get it sooner or later and will stick to it automatically.

tl;dr: write quality answers. They will succeed, as the users will see how they benefit from doing it in the right way.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .