{"action":"created","issue":{"url":"https://api.github.com/repos/magento/magento2/issues/6739","repository_url":"https://api.github.com/repos/magento/magento2","labels_url":"https://api.github.com/repos/magento/magento2/issues/6739/labels{/name}","comments_url":"https://api.github.com/repos/magento/magento2/issues/6739/comments","events_url":"https://api.github.com/repos/magento/magento2/issues/6739/events","html_url":"https://github.com/magento/magento2/issues/6739","id":179022029,"number":6739,"title":"Compiled DI and Developer DI Are Sometimes Incompatible","user":{"login":"maxbucknell","id":1707318,"avatar_url":"https://avatars2.githubusercontent.com/u/1707318?v=4","gravatar_id":"","url":"https://api.github.com/users/maxbucknell","html_url":"https://github.com/maxbucknell","followers_url":"https://api.github.com/users/maxbucknell/followers","following_url":"https://api.github.com/users/maxbucknell/following{/other_user}","gists_url":"https://api.github.com/users/maxbucknell/gists{/gist_id}","starred_url":"https://api.github.com/users/maxbucknell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maxbucknell/subscriptions","organizations_url":"https://api.github.com/users/maxbucknell/orgs","repos_url":"https://api.github.com/users/maxbucknell/repos","events_url":"https://api.github.com/users/maxbucknell/events{/privacy}","received_events_url":"https://api.github.com/users/maxbucknell/received_events","type":"User","site_admin":false},"labels":[{"id":21716835,"url":"https://api.github.com/repos/magento/magento2/labels/acknowledged","name":"acknowledged","color":"02d7e1","default":false},{"id":147131376,"url":"https://api.github.com/repos/magento/magento2/labels/bug%20report","name":"bug report","color":"d93f0b","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-09-24T09:51:03Z","updated_at":"2017-08-23T14:29:36Z","closed_at":null,"body":"### Preconditions\n\nI have found that there are some cases where classes will be introspected by Reflection in the Developer mode, but will not be caught by the `setup:di:compile` command. This increases the testing burden of developers, and produces some very difficult to understand error messages.\n\nAs far as I know, this affects every version of Magento 2.0 and 2.1, but I was using 2.0.8 at the time. The environment is modern and following all best practices, and was replicated across a variety of environments.\n### Steps to reproduce\n1. Inject an automatically generated factory of a non-injectable class that is not part of a Magento module. We were using the `Facebook\\Facebook` class from the [`facebook/graph-sdk` Composer package](https://packagist.org/packages/facebook/graph-sdk).\n2. Run the code with the Developer Mode DI, and it will generate the factory, using the Object Manager. The Object Manager will dynamically use Reflection to inspect which arguments are required, and match them all up. It works like a dream.\n3. Run the code with the Compiled DI, and it generates the factory, and calls the Object Manager in the same way. However, the `Facebook\\Facebook` class is not in the compiled DI information, and the Object Manager will pass in the default constructor arguments, which is just the Object Manager.\n4. The result is some kind of type error. In my case, it was:\n   \n   > ``````\n   > Uncaught TypeError: Argument 1 passed to Facebook\\Facebook::__construct()\n   > must be of the type array, object given```\n   > ``````\n### Expected result\n\nI'm not 100% sure what the correct thing to do here is. If we accept that the behaviour should at least be consistent, our options are to prevent the Developer DI from working with external classes (which I don't like), or to enhance the Compiled DI so that it works with external classes that are referred to through generated classes (I like this one more).\n\nA compromise might be to document it well, or something.\n### Fix\n\nFor anyone stumbling across this issue, it can be fixed by adding an empty class to your module, and having it extend your external class. Tell Anton Kril that I found a use for inheritance.\n\nIf you generate a factory for this class in your module, it will find the parent constructor arguments without issue. You can add a preference into `di.xml` for `Facebook\\Facebook`, to be `My\\Module\\Model\\Facebook`, and everything else just falls into place.\n"},"comment":{"url":"https://api.github.com/repos/magento/magento2/issues/comments/324352374","html_url":"https://github.com/magento/magento2/issues/6739#issuecomment-324352374","issue_url":"https://api.github.com/repos/magento/magento2/issues/6739","id":324352374,"user":{"login":"mcspronko","id":3740515,"avatar_url":"https://avatars1.githubusercontent.com/u/3740515?v=4","gravatar_id":"","url":"https://api.github.com/users/mcspronko","html_url":"https://github.com/mcspronko","followers_url":"https://api.github.com/users/mcspronko/followers","following_url":"https://api.github.com/users/mcspronko/following{/other_user}","gists_url":"https://api.github.com/users/mcspronko/gists{/gist_id}","starred_url":"https://api.github.com/users/mcspronko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcspronko/subscriptions","organizations_url":"https://api.github.com/users/mcspronko/orgs","repos_url":"https://api.github.com/users/mcspronko/repos","events_url":"https://api.github.com/users/mcspronko/events{/privacy}","received_events_url":"https://api.github.com/users/mcspronko/received_events","type":"User","site_admin":false},"created_at":"2017-08-23T14:29:36Z","updated_at":"2017-08-23T14:29:36Z","body":"@antonkril Can you please tell me how composition will help to solve the issue? I am having class with the error, using this class over composition but it shows an error. Thanks."}}
{"actor":{"display_login":"mcspronko"}}