2

Anyone have idea about declare class in __construct and declare class in top of file with use.

Exemple:

use Magento\Store\Model\StoreManagerInterface;

and

public function __construct(
      \Magento\Store\Model\StoreManagerInterface $storeManager,
) {
      $this->_storeManager = $storeManager;
}

marked as duplicate by PЯINCƏ, Manashvi Birla, Dhiren Vasoya, Jai, Priyank Sep 8 '18 at 4:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

If you define the class like below in the top of the page:

use Magento\Store\Model\StoreManagerInterface;

then you __contruct function will be look like this:

public function __construct(
      StoreManagerInterface $storeManager,
) {
      $this->_storeManager = $storeManager;
}

and if you not define the class in top then you can also managed it by injecting directly in your __construct function like below:

public function __construct(
      \Magento\Store\Model\StoreManagerInterface $storeManager,
) {
      $this->_storeManager = $storeManager;
}

Both are same.

Not the answer you're looking for? Browse other questions tagged or ask your own question.