Skip to content

Fixed PHP 8.2 deprecation warnings: 'creation of dynamic property'. #37573

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

Conversation

hostep
Copy link
Contributor

@hostep hostep commented Jun 3, 2023

Description (*)

This fixes PHP 8.2 deprecated usage of 'creation of dynamic property': https://www.php.net/manual/en/migration82.deprecated.php#migration82.deprecated.core.dynamic-properties

The phpstan tool is able to find these problems, here's a copy paste from https://github.com/magento/adobe-commerce-beta/issues/61 where I've reported this a few months ago during the Magento 2.4.6 beta period:

  172    Access to an undefined property Magento\Framework\Error\Processor::$_errorDir.
  173    Access to an undefined property Magento\Framework\Error\Processor::$_reportDir.
  186    Access to an undefined property Magento\Framework\Error\Processor::$_indexDir.
  268    Access to an undefined property Magento\Framework\Error\Processor::$_indexDir.
  269    Access to an undefined property Magento\Framework\Error\Processor::$_errorDir.
  454    Access to an undefined property Magento\Framework\Error\Processor::$_errorDir.
  472    Access to an undefined property Magento\Framework\Error\Processor::$_errorDir.
  475    Access to an undefined property Magento\Framework\Error\Processor::$_errorDir.
  611    Access to an undefined property Magento\Framework\Error\Processor::$_reportDir.
  732    Access to an undefined property Magento\Framework\Error\Processor::$_errorDir.
  176    Access to an undefined property Magento\ImportExport\Model\Export\Entity\AbstractEntity::$_storeIdToCode.
  179    Access to an undefined property Magento\ImportExport\Model\Export\Entity\AbstractEntity::$_storeIdToCode.
  354    Access to an undefined property Magento\ImportExport\Model\Export\Entity\AbstractEntity::$_invalidRows.
  512    Access to an undefined property Magento\ImportExport\Model\Export\Entity\AbstractEntity::$_invalidRows.
  430    Access to an undefined property Magento\Shipping\Model\Carrier\AbstractCarrier::$_result.
  40     Access to an undefined property Magento\Setup\Fixtures\FixturesAsserts\SimpleProductsAssert::$optionRepository.

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes https://github.com/magento/adobe-commerce-beta/issues/61

In the wild, we've only ran into problems with deprecations in the magento/magento-zend-pdf library so far, none of the others we've triggered yet, but that doesn't mean you can't trigger them.

Manual testing scenarios (*)

  • Run vendor/bin/phpstan analyse --level=0 {some-path} | grep 'Access to an undefined property' on all Magento code, it should not output anything (don't run this on the root the M2 codebase, otherwise it will take hours and might crash your computer if you don't have at least 32 GB of memory)
  • Test all affected code and make sure that everything keeps working as expected (I'm assuming the automated tests will take care of this)

Questions or comments

I've used protected scoped members here and there, because I wanted to stay consistent with the existing members in the classes, but not sure if that's recommended and I should maybe change them to private?
Update: changed them to private because the semantic version check failed otherwise.
Update 2: integration tests fail when _storeIdToCode is a private member in AbstractEntity.php, so changed it back to protected which solved the integration tests, however now the Semantic Version check fails again, but in my opinion, this one should be allowed...
Update 3: Same thing for the $_result in AbstractCarrier, had to change it back to protected to solve more integration tests.

The public scopes in pub/errors/processor.php are needed for the integration tests, they directly call those, so we can't make them private.

I won't write new automated tests, because I think that's not relevant in scope of this PR.

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 Jun 3, 2023

Hi @hostep. Thank you for your contribution!
Here are some useful tips on 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
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@hostep
Copy link
Contributor Author

hostep commented Jun 3, 2023

@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 message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@hostep hostep force-pushed the fix-php82-deprecated-dynamic-properties branch from 6614155 to eef6565 Compare June 3, 2023 11:01
@hostep
Copy link
Contributor Author

hostep commented Jun 3, 2023

@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 message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@hostep
Copy link
Contributor Author

hostep commented Jun 3, 2023

Failing unit & functional tests seems to be not related to this PR.
Failing integration tests, I'm not sure, they look suspicious, but I can't seem to figure out how this PR broke them, so let's try them again...

@magento run Integration 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 message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@hostep
Copy link
Contributor Author

hostep commented Jun 3, 2023

@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 message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@hostep hostep force-pushed the fix-php82-deprecated-dynamic-properties branch from d4d384d to b526301 Compare June 5, 2023 05:27
@hostep
Copy link
Contributor Author

hostep commented Jun 5, 2023

@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 message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@hostep hostep force-pushed the fix-php82-deprecated-dynamic-properties branch from b526301 to 137fc85 Compare June 5, 2023 08:18
@hostep
Copy link
Contributor Author

hostep commented Jun 5, 2023

All integration tests should be good now (except for some flaky ones)

@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 message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@hostep
Copy link
Contributor Author

hostep commented Jun 5, 2023

Rest of failing integration test + unit tests are due to some issue in the Usps module, nothing related to this PR.
Failures in functional tests don't look related at first sight (flaky tests probably)

Only the failure in the semantic version checker is related to this PR, that one will need approval I guess?

@engcom-Hotel engcom-Hotel added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Jun 6, 2023
@hostep
Copy link
Contributor Author

hostep commented Jun 6, 2023

Looked a bit more into the failing integration tests with the Usps module, and it might have been caused by changes in this PR. So added some more fixes, by changing accessibility of $_result in the AbstractCarrier from private to protected and removing it from all shipping models, since it's now inherited.

@magento run all tests

@hostep hostep force-pushed the fix-php82-deprecated-dynamic-properties branch from 5a3e18a to ec423eb Compare June 6, 2023 19:06
@hostep
Copy link
Contributor Author

hostep commented Jun 6, 2023

@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 message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@hostep
Copy link
Contributor Author

hostep commented Jun 7, 2023

Alrighty, so that indeed fixed the integration tests, good 🥳

Failures in functional tests don't look related at first sight (flaky tests probably)

Only the failures in the semantic version checker are related to this PR, those will need approval I guess..

@engcom-Lima engcom-Lima added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Jun 7, 2023
@glo71317
Copy link
Contributor

glo71317 commented Aug 9, 2023

Guys, I am processing this pull request internally! Thanks for the contribution!

@magento-devops-reposync-svc magento-devops-reposync-svc merged commit 2ec9059 into magento:2.4-develop Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: ready for testing Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
Status: Recently Merged
Development

Successfully merging this pull request may close these issues.

7 participants