0

I know what object manager is. I know why it is used. I know that as a general rule it shouldn't be used. I know why from reading this. https://devdocs.magento.com/guides/v2.3/extension-dev-guide/object-manager.html#exceptions.

Then I see code like this

https://github.com/magento/magento2/blob/2.3/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Full.php#L83-L85

public function __construct(
 [...]
 $this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(
 ScopeConfigInterface::class
 );
 [...]
}

Which seams like an elegant way of doing it. Especially in something so abstract. So my questions are this:

  • a) Is the above still considered bad practice?

  • b) In this purely to maintain backward compatibility? Or is there another reason?

asked Oct 16, 2019 at 20:59

1 Answer 1

3

a) Yes, it is bad practice

b) Yes, it is purely to maintain backward compatibility

:)

answered Oct 17, 2019 at 1:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.