Magento – Purpose of magento\generated\metadata\global.php file and is it safe to delete this file

magento2module

I encountered the following issue when I have moved Magento 2 module into production with the command setup:di: compile

Uncaught Error: Call to a member function setActive() on boolean in /opt/bitnami/apps/magento/htdocs/vendor/magento/module-backend/Model/View/Result/Page.php:27\nStack trace:
/opt/bitnami/apps/magento/htdocs/generated/code/Magento/Backend/Model/View/Result/Page/Interceptor.php(24): Magento\Backend\Model\View\Result\Page->setActiveMenu('…')

I found a solution to delete magento\generated\metadata\global.php file which worked.

Does anyone know the purpose of global.php file and is it safe to delete it?

Thanks in advance.

Best Answer

As the documentation says

"The code compiler creates generated/metadata/global.php, which is a PHP serialized map of all constructor definitions mixed with object linking configuration defined in di.xml. di.xml is the dependency injection configuration. There is a global app/etc/di.xml and there can one defined for every module ."