my Magento 2 runs in developer mode and I'm trying to install my first selfwritten extension by CLI. The install itself works nice, but when running the setup:upgrade command, it can't find the injected Factories in my UpgradeData.php scripts.

Here a condensed version of the code:

public function _construct(
    \Vendor\Extension\Model\DepartmentFactory $departmentFactory,
    \Vendor\Extension\Model\EmployeeFactory $employeeFactory
    $this->departmentFactory = $departmentFactory;
    $this->employeeFactory = $employeeFactory;
    $salesDepartment = $this->departmentFactory->create();

PHP Fatal error:  Uncaught Error: Call to a member function create() on null in /var/www/html/magento/app/code/Vendor/Extension/Setup/UpgradeData.php:30

Not even the Magento\Framework\Code\Generator\Autoloader is requested at this point. Many other classes are successfully requested an generated while running other setup:upgrade tasks on earlier modules, but here, the Autoloader is not called at all (checked that by echoing in the class).

As far as I understood, neither do I need to write this classes, nor do I have to write a preference for it. Please correct me if I'm wrong.

So what could the problem be? What do I have to change?

Many thanks.


The constructor is defined incorrectly, it should be:

public function __construct(..

With a double underscore for the autoloading / dependency injection to work.

  • What a bummer, I got so confused with Magentos single and double _ conventions. This solved the problem. Many thanks. – Rayina Jun 23 '16 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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