You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Magento 1.9报错求助:__autoload()弃用及布局文件致命错误

Fixing Magento 1.9 Deprecation & Fatal Error on Newer PHP Versions

Let's break down how to fix both issues you're seeing—they're caused by Magento 1.9 not being optimized for PHP 7.2+, which deprecated some legacy functions and tightened up syntax rules.

1. Fixing the __autoload() is deprecated Warning

PHP 7.2+ dropped support for the old __autoload() function in favor of spl_autoload_register(). Here's how to update Magento's core function safely:

  • Never edit core files directly—copy the file to your local code pool first to avoid losing changes during upgrades:
    Copy app/code/core/Mage/Core/functions.php to app/code/local/Mage/Core/functions.php
  • Open the copied file, find line 60 where the __autoload() function is defined. Replace the entire function with:
    spl_autoload_register(function ($class) {
        if (substr($class, 0, 5) === 'Mage_') {
            $classFile = str_replace('_', DS, $class) . '.php';
            include_once Mage::getBaseDir('code') . DS . $classFile;
        } elseif (strpos($class, 'Varien_') !== false) {
            include_once Mage::getBaseDir('lib') . DS . str_replace('_', DS, $class) . '.php';
        }
    });
    
  • Save the file—this replaces the deprecated __autoload() with the recommended spl_autoload_register() approach.

2. Fixing the Function name must be a string Fatal Error

This error occurs because PHP 7+ enforces stricter rules for variable function calls. Let's patch the Layout.php file:

  • Again, copy the core file to your local pool first:
    Copy app/code/core/Mage/Core/Model/Layout.php to app/code/local/Mage/Core/Model/Layout.php
  • Open the copied file and navigate to line 555. The problematic line typically involves a variable method call, like:
    $html = $block->$method();
    
  • Replace that line with a call_user_func() call to make it PHP 7+ compatible:
    $html = call_user_func(array($block, $method));
    
  • If the line is part of a block-rendering loop, double-check that $method is always a string (Magento 1.9 sometimes passes non-string values here in newer PHP environments).

Extra Notes

  • These are quick patches to get Magento 1.9 running on PHP 7.2+. Keep in mind that Magento 1.9 is end-of-life, so for long-term stability, consider upgrading to Magento 2 or using a supported Magento 1 fork.
  • Always back up your files before making changes, and test fixes in a staging environment first!

内容的提问来源于stack exchange,提问作者Nyanla Aung

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:25:30