大家好我想尝试使用spl autoload功能,它在我的本地服务器上工作得很好,但是当我在线时它会返回错误。我纠结它的服务器问题,但我需要有人引导我,看看我有下面的代码
spl_autoload_register(function($class)
{
require_once 'classes/'. $class .'.php';
}
);
和错误
解析错误:语法错误,意外的T_FUNCTION,期待')' 第22行/home/www/ftwrkdesign.com
注意:classes是一个文件夹,它的绝对路径返回相同的错误php服务器版本是5.5.29
答案 0 :(得分:1)
检查php
版本是否支持anonymous functions
,它们仅来自php 5.3
。如果您的版本低于5.3
,则应在将其传递给spl_autoload_register()
之前定义您的功能。
<?php
function qwerty($class){
require_once 'classes/'. $class .'.php';
}
spl_autoload_register('qwerty');
答案 1 :(得分:0)
服务器上的PHP版本不允许使用匿名函数。
这就是解析器在左括号后不允许使用function关键字的原因。