浏览文章

文章信息

Magento2 PHP7.4 "message": "Type Error occurred when creating object: %type"根本原因解析 15048

1、类似报错

{
    "message": "Type Error occurred when creating object: %type",
    "parameters": {
        "type": "Aiweline\\Upsell\\Service\\Apply"
    },
    "trace": "#0 /www/wwwroot/dev.trustonlines.aiweline.com/vendor/magento/framework/ObjectManager/Factory/Compiled.php(108): Magento\\Framework\\ObjectManager\\Factory\\AbstractFactory->createObject()\n#1 /www/wwwroot/dev.trustonlines.aiweline.com/vendor/magento/framework/ObjectManager/Factory/Compiled.php(150): Magento\\Framework\\ObjectManager\\Factory\\Compiled->create()\n#2 /www/wwwroot/dev.trustonlines.aiweline.com/vendor/magento/framework/ObjectManager/Factory/Compiled.php(79): Magento\\Framework\\ObjectManager\\Factory\\Compiled->get()\n#3 /www/wwwroot/dev.trustonlines.aiweline.com/vendor/magento/framework/ObjectManager/Factory/Compiled.php(150): Magento\\Framework\\ObjectManager\\Factory\\Compiled->create()\n#4 /www/wwwroot/dev.trustonlines.aiweline.com/vendor/magento/framework/ObjectManager/Factory/Compiled.php(79): Magento\\Framework\\ObjectManager\\Factory\\Compiled->get()\n#5 /www/wwwroot/dev.trustonlines.aiweline.com/vendor/magento/framework/ObjectManager/ObjectManager.php(70): Magento\\Framework\\ObjectManager\\Factory\\Compiled->create()\n#6 /www/wwwroot/dev.trustonlines.aiweline.com/vendor/magento/module-webapi/Controller/Rest/SynchronousRequestProcessor.php(90): Magento\\Framework\\ObjectManager\\ObjectManager->get()\n#7 /www/wwwroot/dev.trustonlines.aiweline.com/vendor/magento/module-webapi/Controller/Rest.php(188): Magento\\Webapi\\Controller\\Rest\\SynchronousRequestProcessor->process()\n#8 /www/wwwroot/dev.trustonlines.aiweline.com/vendor/magento/framework/Interception/Interceptor.php(58): Magento\\Webapi\\Controller\\Rest->dispatch()\n#9 /www/wwwroot/dev.trustonlines.aiweline.com/vendor/magento/framework/Interception/Interceptor.php(138): Magento\\Webapi\\Controller\\Rest\\Interceptor->___callParent()\n#10 /www/wwwroot/dev.trustonlines.aiweline.com/vendor/magento/framework/Interception/Interceptor.php(153): Magento\\Webapi\\Controller\\Rest\\Interceptor->Magento\\Framework\\Interception\\{closure}()\n#11 /www/wwwroot/dev.trustonlines.aiweline.com/generated/code/Magento/Webapi/Controller/Rest/Interceptor.php(26): Magento\\Webapi\\Controller\\Rest\\Interceptor->___callPlugins()\n#12 /www/wwwroot/dev.trustonlines.aiweline.com/vendor/magento/framework/App/Http.php(116): Magento\\Webapi\\Controller\\Rest\\Interceptor->dispatch()\n#13 /www/wwwroot/dev.trustonlines.aiweline.com/generated/code/Magento/Framework/App/Http/Interceptor.php(24): Magento\\Framework\\App\\Http->launch()\n#14 /www/wwwroot/dev.trustonlines.aiweline.com/vendor/magento/framework/App/Bootstrap.php(263): Magento\\Framework\\App\\Http\\Interceptor->launch()\n#15 /www/wwwroot/dev.trustonlines.aiweline.com/index.php(51): Magento\\Framework\\App\\Bootstrap->run()\n#16 {main}"
}


2、原因以及解决

此类错误是Magento系统在生成该类时遇到PHP类检查的错误,这种错误是PHP类中的错误,也就是说本身PHP类写错了,无法被Magento生成实例

1、常见是PHP7.4强类型下的属性类型错误(实例化了一个与定义属性类型不一样的类,但是却强行赋值给属性

2、类中实例化了不存在的类

3、其他错误的PHP类语法




原创