我从来没有真正玩过类,但我想使用 php-ews在我正在使用 atm 的页面上。
我的主文件通过 include 调用 5 个“根”php 文件
include ("php-ews/ExchangeWebServices.php");
include ("php-ews/EWS_Exception.php");
include ("php-ews/EWSType.php");
include ("php-ews/NTLMSoapClient.php");
include ("php-ews/NTLMStream.php");
然而,在这种情况下,这些提示子文件夹中的文件不包括在内。
Fatal error: Class 'EWSType_FindItemType' not found in C:\wamp\www\intranet\dashboard\mailtest.php on line 19
我已尝试将上述文件包含在 EWSType.php 文件中,然后它提示未包含下一个文件。我已经尝试过在文件夹中包含任何 .php 的方法,但没有用。
我假设我只是想加载一个错误的类,想知道是否有人可以告诉我方法!
最佳答案
与其手动加载类,不如尝试__autoload
加载它们。这样您就不必担心保留包含列表。自动加载器将为您完成。
如果类文件的调用方式与类本身相同,应该很容易。
参见 http://php.net/manual/en/function.spl-autoload-register.php 和 http://de3.php.net/manual/en/language.oop5.autoload.php详情
function ews_autoloader($className) {
if($className != 'EWS_Exception') {
$classPath = str_replace('_','/',$className);
}
if(file_exists("php-ews/{$classPath}.php") {
include("php-ews/{$classPath}.php");
}
}
spl_autoload_register('ews_autoloader');
关于php - 加载类 EWSType_FindItemType (php-ews) 时出现 fatal error ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7027375/