magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Support the use of PHP 8.0 "mixed" type

Open pmzandbergen opened this issue 3 years ago • 19 comments

Currently Magento does not compile when using the mixed type, neither as a parameter or return type. The generated Interceptor / Proxy / etc. classes try to make this union type nullable (?mixed). This will result in a fatal PHP error since the union type already includes null, and null is not nullable.

During compilation you will be encountered with the following error: Type "mixed" cannot be nullable

This patch checks if the type is mixed before adding the nullable (?) prefix.

Resolved issues:

  1. [x] resolves magento/magento2#35579: Support the use of PHP 8.0 "mixed" type

pmzandbergen avatar Jun 02 '22 14:06 pmzandbergen

Hi @pmzandbergen. 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

:exclamation: 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

:information_source: Run only required test builds during development. Run all test builds before sending your pull request for review.

For more details, review the Magento Contributor Guide documentation.

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

:clock10: You can find the schedule on the Magento Community Calendar page.

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

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

m2-assistant[bot] avatar Jun 02 '22 14:06 m2-assistant[bot]

Hi @pmzandbergen ! Could you please share your use case/code snipped to reproduce this issue ?

Thanks, Maksym

xmav avatar Jun 02 '22 17:06 xmav

Hi @pmzandbergen ! Could you please share your use case/code snipped to reproduce this issue ?

Thanks, Maksym

Created a very simple example module @ https://github.com/pmzandbergen/some-module

Simply add it to a vanilla Magento 2.4.4 installation and run bin/magento setup:di:compile. Output:

% bin/magento setup:di:compile                        
Compilation was started.
Interceptors generation... 4/9 [============>---------------]  44% 4 secs 218.0 MiB
In Generator.php line 140:
                                                                                                                                                                                                                
  Type "mixed" cannot be nullable                                                                                                                                                                               
  Class Some\Module\Model\TestClass\Interceptor generation error: The requested class did not generate properly, because the 'generated' directory permission is read-only. If --- after running the 'bin/mage  
  nto setup:di:compile' CLI command when the 'generated' directory permission is set to write --- the requested class did not generate properly, then you must add the generated class object to the signature  
   of the related construct method, only.                                                                                                                                                                       
                                                                                                                                                                                                                

setup:di:compile

This is caused by Magento using ?mixed as a parameter type for the Interceptor for Some\Module\Model\TestClass

pmzandbergen avatar Jun 03 '22 06:06 pmzandbergen

Hi @pmzandbergen, Could you please cover your changes with integration tests?

ihor-sviziev avatar Jun 06 '22 08:06 ihor-sviziev

@magento run all tests @magento create issue

ihor-sviziev avatar Jun 06 '22 08:06 ihor-sviziev

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.

Hi @pmzandbergen, Could you please cover your changes with integration tests?

Of course. I'll add tests at the end of this week.

pmzandbergen avatar Jun 07 '22 13:06 pmzandbergen

@ihor-sviziev sorry didn't had time to add tests yet, also holiday around the corner. I'll try to find some time afterwards.

pmzandbergen avatar Jul 13 '22 13:07 pmzandbergen

We stumbled across the same error, and it seems to happen only in developer mode as soon as there is a class which uses mixed as a return type and has plugins. di:compile works in our case.

amenk avatar Jul 29 '22 10:07 amenk

@ihor-sviziev found some spare time, writing a test now :)

pmzandbergen avatar Aug 05 '22 06:08 pmzandbergen

@ihor-sviziev added test based on the proxy generator (all other generators will work the same way).

Note: The test will be skipped on PHP version < 8.0.0

pmzandbergen avatar Aug 05 '22 08:08 pmzandbergen

@magento run all tests

ihor-sviziev avatar Aug 05 '22 11:08 ihor-sviziev

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 run Static Tests

ihor-sviziev avatar Aug 09 '22 12:08 ihor-sviziev

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 run all tests

ihor-sviziev avatar Aug 09 '22 21:08 ihor-sviziev

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.

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.

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.

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.

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.

:heavy_check_mark: QA Passed

Preconditions: Install fresh vanilla Magento 2.4-develop

Manual testing scenario:

  1. Go to https://github.com/pmzandbergen/some-module and download "some modules".
  2. Copy the module to app/code (app/code/Some/Module/...)
  3. Enable the module bin/magento module:enable Some_Module
  4. Run compiler bin/magento setup:di:compile

Before: :heavy_multiplication_x: Getting error while compiling. Screenshot from 2022-08-25 14-35-39

After: :heavy_check_mark: No error while compilation. Screenshot from 2022-08-25 14-45-31

Additionally tested:

  1. Login as admin.
  2. Create order from admin.
  3. Login as customer.
  4. Place an order from customer.
  5. Created invoice,shipped and credit memo.

engcom-Lima avatar Aug 25 '22 11:08 engcom-Lima