Skip to content

Replaced PHP8-only str_contains method. #33886

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

Merged
merged 4 commits into from
Oct 28, 2021

Conversation

reense
Copy link
Contributor

@reense reense commented Aug 23, 2021

Description (*)

This PR removes the PHP8-only method str_contains and replaces it with the traditional stripos() check with false, which is available since PHP5.

The reason for using this older method are the Magento 2.4 system requirements: Magento 2.4 supports PHP7.4 which does not contain the str_contains method source. The latest version of Magento, 2.4.3, does not even support PHP 8 source.

This issue has to be fixed, since it breaks upgrading a Magento instance on PHP 7.4. (see Manual error-reproducing scenario)

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes Unsupported PHP 8 command in Magento  #33680
  2. Fixes Magento 2.4.2 to 2.4.3 Upgrade Issue use php 8 function #33755
  3. Fixes Error with PHP 8 str_contains function when upgrade to 2.4.3 #33945

Manual error-reproducing scenario

  1. Create a Magento installation on any version lower than 2.4.3.
  2. Use PHP 7.4.
  3. Run composer require magento/product-community-edition=2.4.3 --no-update
  4. Run composer update
  5. The update fails; saying call to undefined method str_contains().

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Aug 23, 2021

Hi @reense. Thank you for your contribution
Here are some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

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

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@m2-community-project m2-community-project bot added Priority: P0 This generally occurs in cases when the entire functionality is blocked. Severity: S1 Affects critical data or functionality and forces users to employ a workaround. labels Aug 23, 2021
@bgorski bgorski self-requested a review August 23, 2021 11:17
@bgorski bgorski self-assigned this Aug 23, 2021
@bgorski bgorski added the Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests label Aug 23, 2021
@magento-engcom-team
Copy link
Contributor

Hi @bgorski, thank you for the review.
ENGCOM-9192 has been created to process this Pull Request

@magento-engcom-team
Copy link
Contributor

@reense thank you for contributing. Please accept Community Contributors team invitation here to gain extended permissions for this repository.

@bgorski
Copy link
Contributor

bgorski commented Aug 24, 2021

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@ihor-sviziev
Copy link
Contributor

I just updated the PR to be equal to the official hotfix described here:
https://support.magento.com/hc/en-us/articles/4408021533069-Adobe-Commerce-upgrade-2-4-3-2-3-7-p1-PHP-Fatal-error-Hotfix
@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@magento-engcom-team
Copy link
Contributor

Hi @Den4ik, thank you for the review.
ENGCOM-9192 has been created to process this Pull Request

@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, thank you for the review.
ENGCOM-9192 has been created to process this Pull Request

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@engcom-Alfa
Copy link
Contributor

engcom-Alfa commented Sep 29, 2021

I tried to reproduce the issue using 2.4-develop and could not reproduce at all! But there is a way I found out to check the str_contains() function compatibility

  1. Disabled the str_contains() if statement block completely from the /vendor/symfony/polyfill-php80/bootstrap.php class, then executed the upgrade command.
  2. Definitely we get the error as defined in this reported PR.

Well, updated PR code changes will help in resolving the issue as well where we have to reset the bootstrap.php class changes before the re execution!
@ihor-sviziev @reense @engcom-Hotel

@engcom-Alfa
Copy link
Contributor

✔️ QA Passed

Preconditions:

  1. Should have an Magento instance installed

Manual testing scenario:

  1. Since couldn't reproduce as same as description steps, could able to check the str_contains() issue as mentioned in above comments.

Before: ✖️ str_contains() - a php8 version method was used
image

After: ✔️ Backed the code to php7 version one

Successfully executed all import/composer update/ upgrade commands without any issues

There is no additional testing is required as the fix was related to a one line of code that was impacted due to version change, and the 2.4.2-p2 code has been used back to solve the issue. Hence no regression is require as all the automation testing jobs are working fine.

@engcom-Alfa
Copy link
Contributor

@magento give me test instance

@magento-deployment-service
Copy link

Hi @engcom-Alfa. Thank you for your request. I'm working on Magento instance for you.

@magento-deployment-service
Copy link

@m2-assistant
Copy link

m2-assistant bot commented Oct 28, 2021

Hi @reense, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests Award: bug fix Component: Filesystem Priority: P0 This generally occurs in cases when the entire functionality is blocked. Progress: accept Release Line: 2.4 Severity: S1 Affects critical data or functionality and forces users to employ a workaround.
Projects
None yet
9 participants