Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkout page dies to an exception if \Magento\Paypal\Model\Info is extended with plugins. \Magento\Backup\Model\Backup affected as well. #9167

Closed
eerorika opened this issue Apr 7, 2017 · 3 comments
Assignees
Labels
bug report Component: Payment Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development

Comments

@eerorika
Copy link

eerorika commented Apr 7, 2017

The bug is a bit more general, than the immediate effects. The bug manifests in any class that contains a public method that returns by reference. \Magento\Paypal\Model\Info and \Magento\Backup\Model\Backup are only such classes that I found in Magento CE 2.1.4.

The bug would also manifest in any class with a public method what declares the return type. I didn't find any such classes in core Magento code.

The bug is caused by old version of Zend code generation that doesn't support the new features introduced in PHP 7. The generated interceptor lacks the correct return type, and that violates PHP rules. The exact class that does the generation is vendor/zendframework/zend-code/src/Generator/MethodGenerator.php. An updated version of the library that supports PHP 7 can be found here.

A proper fix is to upgrade Zend code generator (or backport the changes), but a workaround is to skip affected functions:

--- vendor/magento/framework/Interception/Code/Generator/Interceptor.php
+++ vendor/magento/framework/Interception/Code/Generator/Interceptor.php
@@ -90,6 +90,8 @@
         return !($method->isConstructor() ||
             $method->isFinal() ||
             $method->isStatic() ||
+            $method->returnsReference() ||
+            $method->hasReturnType() ||
             $method->isDestructor()) && !in_array(
                 $method->getName(),
                 ['__sleep', '__wakeup', '__clone']

Preconditions

Reproduced on Magento CE 2.1.4. Other versions probably affected as well.

Steps to reproduce

  1. Create module with following di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="\Magento\Paypal\Model\Info">
        <plugin type="\Magento\Framework\DataObject" name="Test::Info" />
    </type>
</config>
  1. Enable Paypal payment method.
  2. Go to checkout.

Expected result

Checkout page should be shown.

Actual result

1 exception(s):
Exception #0 (Exception): Warning: Declaration of Magento\Paypal\Model\Info\Interceptor::exportFromPayment(Magento\Payment\Model\InfoInterface $payment, $to, array $map = NULL) should be compatible with & Magento\Paypal\Model\Info::exportFromPayment(Magento\Payment\Model\InfoInterface $payment, $to, array $map = NULL) in /home/user/site/var/generation/Magento/Paypal/Model/Info/Interceptor.php on line 7

Exception #0 (Exception): Warning: Declaration of Magento\Paypal\Model\Info\Interceptor::exportFromPayment(Magento\Payment\Model\InfoInterface $payment, $to, array $map = NULL) should be compatible with & Magento\Paypal\Model\Info::exportFromPayment(Magento\Payment\Model\InfoInterface $payment, $to, array $map = NULL) in /home/user/site/var/generation/Magento/Paypal/Model/Info/Interceptor.php on line 7
#0 /home/user/site/var/generation/Magento/Paypal/Model/Info/Interceptor.php(7): Magento\Framework\App\ErrorHandler->handler(2, 'Declaration of ...', '/home/user/ka...', 7, Array)
#1 /home/user/site/vendor/magento/framework/Code/Generator/Io.php(158): include('/home/user/ka...')
#2 /home/user/site/vendor/magento/framework/Code/Generator.php(118): Magento\Framework\Code\Generator\Io->includeFile('/home/user/ka...')
#3 /home/user/site/vendor/magento/framework/Code/Generator/Autoloader.php(35): Magento\Framework\Code\Generator->generateClass('Magento\\Paypal\\...')
#4 [internal function]: Magento\Framework\Code\Generator\Autoloader->load('Magento\\Paypal\\...')
#5 [internal function]: spl_autoload_call('Magento\\Paypal\\...')
#6 /home/user/site/vendor/magento/framework/Code/Reader/ClassReader.php(19): ReflectionClass->__construct('Magento\\Paypal\\...')
#7 /home/user/site/vendor/magento/framework/ObjectManager/Definition/Runtime.php(44): Magento\Framework\Code\Reader\ClassReader->getConstructor('Magento\\Paypal\\...')
...
@YevSent
Copy link
Contributor

YevSent commented Apr 7, 2017

Hi, @eerorika, thanks for reporting. It's known the issue about outdated Zend Code library and PHP 7 features, we already have a task to upgrade Zend Code (internal ticket MAGETWO-66512).

I've created separated internal ticket (MAGETWO-67260) for the issue with methods which return references.

@YevSent YevSent added 2.1.x Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Component: Payment bug report labels Apr 7, 2017
magento-team pushed a commit that referenced this issue May 3, 2017
@alena-marchenko
Copy link

Hi @eerorika

Fix for MAGETWO-67260 is merged to develop branch, closing the issue.
Thank you!

@korostii
Copy link
Contributor

korostii commented May 4, 2017

Hi @alena-marchenko,

Could you please provide an answer to the following questions:

  1. Is there any official timeline for the 2.2 release which you could announce publicly?
  2. Could you please briefly explain, what's the recommended way of using the fixes provided for the develop branch if you're a merchant or an integrator currently running 2.1.x CE in production? A link to documentation would be perfect (if available).

Background for my questions:
I've seen numerous issues closed with the reason "merged to develop branch" and as I understand, develop branch corresponds to the future 2.2 version and there seems to be no publicly available date for its release. Many of those bugfixes don't reach 2.1.x releases for months straight.

To be honest, I don't see how is "merged to develop branch" an acceptable resolution to an acknowledged bug. Until the fix is officially released, a lot of the users are still struggling with it.
In my opinion, having these patches added into the nearest 2.1.x (or 2.1.x.x) releases right away would be perfect, but that doesn't seem to be happening for quite a lot of similar issues out here in on Magento2's GitHub.

Considering that the switch to 2.2 will probably be somewhat resource-heavy and very delayed, it would make sense to have an alternative suggested officially to users of 2.1.x which would help use these numerous fixes in a safe and robust way (of which there seems to be none, to the best of my knowledge).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Payment Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

No branches or pull requests

4 participants