magento2
magento2 copied to clipboard
Support the use of PHP 8.0 "mixed" type
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:
- [x] resolves magento/magento2#35579: Support the use of PHP 8.0 "mixed" type
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:
Database CompareFunctional Tests CEFunctional Tests EE,Functional Tests B2BIntegration TestsMagento Health IndexSample Data Tests CESample Data Tests EESample Data Tests B2BStatic TestsUnit TestsWebAPI TestsSemantic 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
Hi @pmzandbergen ! Could you please share your use case/code snipped to reproduce this issue ?
Thanks, Maksym
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
Hi @pmzandbergen, Could you please cover your changes with integration tests?
@magento run all tests @magento create issue
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.
@ihor-sviziev sorry didn't had time to add tests yet, also holiday around the corner. I'll try to find some time afterwards.
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.
@ihor-sviziev found some spare time, writing a test now :)
@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
@magento run all tests
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
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
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:
- Go to https://github.com/pmzandbergen/some-module and download "some modules".
- Copy the module to app/code (app/code/Some/Module/...)
- Enable the module
bin/magento module:enable Some_Module - Run compiler
bin/magento setup:di:compile
Before: :heavy_multiplication_x: Getting error while compiling.

After: :heavy_check_mark: No error while compilation.

Additionally tested:
- Login as admin.
- Create order from admin.
- Login as customer.
- Place an order from customer.
- Created invoice,shipped and credit memo.