Magento2: The php7 feature of using 'self' as return type results in fatal error (on seup:di:compile)

Created on 5 Sep 2019  路  7Comments  路  Source: magento/magento2

_(Re-reporting an issue with even simpler steps)_

This report addresses an issue that has been talked about before, but has not yet received a solution that would be viable in the long run as the focus has been mostly on making sure that Magento2 code does not use certain PHP7 features rather than making Framework fully capable of supporting all that PHP7 has to offer.

Therefore the description has been written in a form where existing code is manipulated with to make sure that there's no way to perceive this as a issue that deserves a solution of removing the appearance of the problem (which is fine as an isolated containment of the issue but I would humbly advise against closing the ticket based on said containment).

Same issue reported in different scenarios in:

https://github.com/magento/magento2/issues/24443
https://github.com/magento/magento2/issues/22769
https://github.com/magento/magento2/issues/23084
https://github.com/magento/magento2/issues/11905

This issue created on purpose to have an open issue on this topic as all that were previously reported have since been closed (with "fixed" flag).

Environment

  1. OS: Ubuntu 18.04.2 LTS (Bionic Beaver)
  2. PHP: 7.2.19-0ubuntu0.18.04.1 (Bionic Beaver default);
    Other聽7.2 releases are OK as well
    No other PHP version needs to be tested.
  3. Php error reporting level (in /etc/php/7.2/cli/php.ini) configured as follows:
    error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT

Preconditions

_(this guide has been written and tested by following ONLY the steps provided with no manual/custom actions taken)_

  1. Use any Magento release (report based on 2.3.2, which at the time of reporting was the latest release), sample data not needed.

    composer create-project magento/community-edition issue-24475
    cd issue-24475
    bin/magento module:enable --all
    

Steps to reproduce

_(All actions performed in terminal, re-creating issue that was hidden away with the change HERE)_

  1. Modify Magento\Framework\HTTP\PhpEnvironment\Response :: setHeader method by adding a 'self' return type to it:

    sed -i \
    's/\(ion setHeader(.*\)/\1: self/g' \
    lib/internal/Magento/Framework/HTTP/PhpEnvironment/Response.php
    
  2. Trigger聽code generation with:

    bin/magento setup:di:compile
    

Expected result

  1. The code generation command finishes without issues

  2. Proxy (_generated/code/Magento/Framework/Webapi/Rest/Response/Proxy.php_)聽reads:

setHeader(
    $name, 
    $value, 
    $replace = false
) : \Magento\Framework\HTTP\PhpEnvironment\Response

Actual result

  1. The code generation command crashes (error peppered with new-lines to make it easier to read)
Fatal error: Declaration of 

Magento\Framework\Webapi\Rest\Response\Proxy::setHeader(
    $name, 
    $value, 
    $replace = false
): Magento\Framework\Webapi\Rest\Response 

must be compatible with

Magento\Framework\HTTP\PhpEnvironment\Response::setHeader(
    $name, 
    $value, 
    $replace = false
): Magento\Framework\HTTP\PhpEnvironment\Response 
  1. Proxy聽(_generated/code/Magento/Framework/Webapi/Rest/Response/Proxy.php_) reads:
setHeader(
    $name, 
    $value, 
    $replace = false
) : \Magento\Framework\Webapi\Rest\Response

Proposed solutions

  • (the most awesome one) Support for聽all PHP7+ features within the code-generator. Proposed fix is available in the comments of an earlier聽issue HERE.
  • Magento Developer聽Documentation stating that 'self' is not supported and should be avoided at all cost. Providing also an alternative solution (like this one HERE)
  • Code Generator to give an error that 'self' is not supported and should not be used.
FrameworCode Confirmed P2 ready for dev Reproduced on 2.3.x S2 Dev.Experience

All 7 comments

Hi @allanpaiste. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • [x] Summary of the issue
  • [x] Information on your environment
  • [x] Steps to reproduce
  • [x] Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@allanpaiste do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [x] yes
  • [ ] no

Hi @engcom-Charlie. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

If this one also gets closed, then I will give up ;)

@allanpaiste i confirm this issue, thanks for contributing!

:white_check_mark: Confirmed by @engcom-Charlie
Thank you for verifying the issue. Based on the provided information internal tickets MC-19911 were created

Issue Available: @engcom-Charlie, _You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself._

Hi @EugenMerzhka. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • [ ] 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
  • [ ] 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 3. If the issue is not relevant or is not reproducible any more, feel free to close it.


I have no time to properly test this, but I am 99% sure this would fix this issue:
https://github.com/magento/magento2/issues/22769#issuecomment-499387177

Was this page helpful?
0 / 5 - 0 ratings