dps123456789 2016-07-12 21:47
浏览 77
已采纳

PHP:在webserver上提供空白页面(错误500),但在本地(Smarty模板引擎)上工作正常

I have a website that is built with Smarty 3 template engine in PHP 7, and when uploading it to the web server (Apache), it serves a blank page instead of the constructed html. The website works 100% perfect in the local environment, but the server seems to not like something going on.

The output I get when using,

ini_set('display_errors', 1);
error_reporting(E_ALL + E_NOTICE);
echo('<br>PHP version:' . phpversion());

is,

PHP version: 5.2.9

Fatal error: Call to undefined function spl_autoload_register() in /www/mydomain.com/html/assets/inc/vendor/smarty/Autoloader.php on line 81

Now I am positive that the two different versions of PHP aren't causing this issue, as I have uploaded and run other .php files to the server in the past (PHP 7 as well), and they display fine to the client.

What I am not understanding is how the spl_autoload_register() function is not defined because the function is definitely there on line 81 of Autoloader.php, and it's not like it isn't available to the version of PHP running on the webserver (see the docs).

Is it maybe the /html path?. The /html directory on the webserver is where the index.* file goes along with all the other pages and their assets, so I am not putting them in the wrong spot... but why is the path going from /www/mydomain.com into /html, shouldn't it be going right into /assets?

Really hope this made sense, thank you in advance!

  • 写回答

1条回答 默认 最新

  • drhib62644 2016-07-12 21:57
    关注

    Call to undefined function spl_autoload_register()

    do it in index.php file:

    <?php phpinfo(); die;
    

    You'll see that SPL extension does not exist.

    Maybe SPL extension not installed when was compiled from sources.

    Just install new version of PHP (better 5.6) and problem will disappear.

    or better upgrade Your packages:

    Debian, Ubuntu and etc deb based:

    apt-get update
    apt-get upgrade
    apt-get dist-upgrade
    

    Arch, Gentoo and etc:

    pacman -Syu
    

    I'm Arch Linux user and have no problems with fresh stuff. (:



    p.s. at last switch to normal web server or at least DigitalOcean droplet, AWS EC2 instance and etc to have full control on server and libs.

    Also You can replace spl_autoload_register with replacement.

    create a file called spl_autoload_register.php in relative folder and put this code:

    <?php
    
    if (!function_exists('spl_autoload_register')):
        $_spl_autoloaders = array();
    
        /**
         * Autoloader compatibility callback.
         */
        function __autoload($classname)
        {
            global $_spl_autoloaders;
            foreach ($_spl_autoloaders as $autoloader) {
                if (!is_callable($autoloader)) {
                    continue;
                }
    
                call_user_func($autoloader, $classname);
    
                if (class_exists($classname, false)) {
                    return;
                }
            }
        }
    
        /**
         * Register a function to be autoloaded.
         */
        function spl_autoload_register($autoload_function, $throw = true, $prepend = false) {
            if ($throw && !is_callable($autoload_function)) {
                throw new Exception('Function not callable');
            }
    
            global $_spl_autoloaders;
    
            if (in_array($autoload_function, $_spl_autoloaders)) {
                return;
            }
    
            if ($prepend) {
                array_unshift($_spl_autoloaders, $autoload_function);
                return;
            }
    
            $_spl_autoloaders[] = $autoload_function;
        }
    
        /**
         * Unregister an autoloader function.
         */
        function spl_autoload_unregister($function) {
            global $_spl_autoloaders;
    
            foreach ($_spl_autoloaders as &$autoloader) {
                if ($autoloader === $function) {
                    unset($autoloader);
                    return true;
                }
            }
            return false;
        }
    
        /**
         * Get the registered autoloader functions.
         */
        function spl_autoload_functions() {
            return $GLOBALS['_spl_autoloaders'];
        }
    endif;
    

    and then in top of main file of Your app require it:

    require_once 'spl_autoload_register.php';
    

    this code will replace missing spl_autoload_register function with custom one that works identically same.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵