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()
對象的方法,但對於全局函數我無法找到任何東西。這樣的事情是否存在,還是我必須將所有這些額外的功能都放在某個頭文件中?