0
我一直遇到问题,我想使用一个有用的功能,如str_getcsv()
或quoted_printable_encode()
,但发现它仅在PHP 5.3之间出现。我想让我编写的代码至少兼容5.2,但我不想编写一堆专门的代码。__autoload()等价于非类功能?
我已经从PHP.net注释中获得了习惯抓取替身函数,将它们存储在如func.quoted_printable_encode.php
这样的有用名称的文件中,并在每个我想要调用它们的地方编写如下所示的块。
if(! function_exists('quoted_printable_encode')) {
$funcfile = 'func.quoted_printable_encode.php';
if(file_exists($funcfile) && is_readable($funcfile)) {
require('func.quoted_printable_encode.php');
} else {
Throw new Exception('Cannot invoke function: quoted_printable_encode');
}
}
这似乎极其相似__autoload()
上课,并为__call()
对象的方法,但对于全局函数我无法找到任何东西。这样的事情是否存在,还是我必须将所有这些额外的功能都放在某个头文件中?