-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Closed
Labels
Component: Framework/SetupUSE ONLY for FRAMEWORK RELATED BUG! E.g If bug occurs during Catalog Setup use just CatalogUSE ONLY for FRAMEWORK RELATED BUG! E.g If bug occurs during Catalog Setup use just CatalogFixed in 2.4.xThe issue has been fixed in 2.4-develop branchThe issue has been fixed in 2.4-develop branchIssue: Format is validGate 1 Passed. Automatic verification of issue format passedGate 1 Passed. Automatic verification of issue format passed
Description
Preconditions (*)
The current implementation of \Magento\Setup\Module\Di\Code\Scanner\PhpScanner
does not support classes that contain anonymous classes. This leads to failures for di:setup:compile
command. The problem that PhpScanner
treats anonymous classes as classes that might require code generation for factories and extension attributes.
All Magento versions have this issue.
Steps to reproduce (*)
- Create a dummy class which contains an anonymous class, like
Magento\DummyModule\Dummy
(see a sample below) - Run
bin/magento setup:di:compile
CLI command
Expected result (*)
- Compilation is successful
Actual result (*)
- Compilation fails with an error
Class \Magento\DummyModule\$arg does not exist
Sample class:
namespace Magento\DummyModule;
class Dummy
{
public function execute($arg)
{
return new class($arg) {
private $arg;
public function __construct($arg)
{
$this->arg = $arg;
}
public function serialize()
{
return (string) $this->arg;
}
};
}
}
To achieve the same error as described in #21555, the anonymous class should not provide a possibility to specify arguments for a constructor. In simple words, return new class {
.
Metadata
Metadata
Assignees
Labels
Component: Framework/SetupUSE ONLY for FRAMEWORK RELATED BUG! E.g If bug occurs during Catalog Setup use just CatalogUSE ONLY for FRAMEWORK RELATED BUG! E.g If bug occurs during Catalog Setup use just CatalogFixed in 2.4.xThe issue has been fixed in 2.4-develop branchThe issue has been fixed in 2.4-develop branchIssue: Format is validGate 1 Passed. Automatic verification of issue format passedGate 1 Passed. Automatic verification of issue format passed