Magento is designed to use PHP 7, newest versions even 7.1. Actually one of the most killing feature - return types doesn't work well with Magento implementation of Proxy object.

For example I create proxy for some dependency of class. This dependency has a few methods and at least one of them contains return type. It will fail later as the proxy won't copy return type at all, and declarations of methods in original and proxy class won't match. Has some figured out something to make it work? Or is it question for core team as request for bug fix?


It is a question for core team as a request for improvement ;).

Or as better solution, you can fix it by self and contribute it to Magento over Pull Request


This has been annoying me for some time now as well. Magento 2.3.0 is now only a week away and as I understand it, the solution will shipped there: https://github.com/magento/magento2/blob/2.3-develop/lib/internal/Magento/Framework/ObjectManager/Code/Generator/Proxy.php#L186 In short, proxy generation will include the proper return types declared in the original source.

The current code in Magento 2.3 is a bit more complex, but you can hack something equal in your source (err, no argument here) by modifying the _getMethodInfo method of the Magento\Framework\ObjectManager\Code\Generator\Proxy class. And then, in the $methodInfo add a line like 'returnType' => $method->getReturnType(),. That being said, hacking the core is pointless but a similar solution will be shipped in Magento 2.3.

  • Agreed, pointless at current time :) – Bartosz Kubicki Nov 25 '18 at 17:54

@Jisse @KAndy, actually I have checked that in 2.3.0 by myself and I confirm, that this is working. What is more I even contribute and fixed code for case when variadic argument in proxied class method is used.

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.