Skip to content

Di:Compile - Compiled Codes Di has wrong Instances of Arguments for Construct #5954

Closed
@antbates91

Description

@antbates91

Preconditions

  1. Magento 2.1 Enterprise (https://github.com/magento/magento2/releases/tag/2.1.0)
  2. Dev Environment - PHP 7.0.8, MySQL 5.6.10
  3. Production Environment (Staging/Dev) - PHP 7.08, MySQL 5.6.28

Steps to reproduce

  1. Create a module extending the class Magento\Framework\View\Element\Html\Links
  2. Add the following construct.
public function __construct(Context $context, Session $session)
    {
        $this->session = $session;
        parent::__construct($context);
    }

Where the types are defined at the top of the file as:

use Magento\Framework\View\Element\Html\Links as MagentoLinks;
use Magento\Customer\Model\Session;
use Magento\Framework\View\Element\Template\Context;
  1. Run di:compile.
  2. Confirm the result is as follows:
php bin/magento setup:di:compile
Compilation was started.
Interception cache generation... 7/7 [============================] 100% 6 mins 318.0 MiBB0 MiB
Generated code and dependency injection configuration successfully.
  1. Load up a template with a Block type from your newly created Links class that extends the magento version in your browser.
  2. The following error is displayed:
Fatal error: Uncaught TypeError: Argument 1 passed to ModName\Framework\View\Element\Html\Links::__construct() must be an instance of Magento\Framework\View\Element\Template\Context, instance of Magento\Framework\ObjectManager\ObjectManager given, called in /domains/***.com/___deploy/releases/20160728154029/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 93 and defined in /domains/***.com/___deploy/releases/20160728154029/app/code/ModName/Framework/View/Element/Html/Links.php:20 Stack trace: #0 /domains/***.com/___deploy/releases/20160728154029/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(93): ModName\Framework\View\Element\Html\Links->__construct(Object(Magento\Framework\ObjectManager\ObjectManager)) #1 /domains/***.com/___deploy/releases/20160728154029/vendor/magento/framework/ObjectManager/Factory/Compiled.php(88): Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject('ModName in /domains/***.com/___deploy/releases/20160728154029/app/code/ModName/Framework/View/Element/Html/Links.php on line 20

I have a attached a screenshot of the arguments being passed into the create function for Magento\Framework\ObjectManager\Factory\Compiled.

arguments

Expected result

  1. The template file should load without an issue. It does before you use the compiler.

Actual result

  1. The frontend of Magento will error with the above message.

Delete the var/di directory and the file works fine, recompile again and it breaks. This happens on a local dev environment, and a production dev/staging environment.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions