Fatal error: Class 'adLDAP' not found

拟墨画扇 提交于 2019-12-11 03:45:58

问题


The file I'm viewing is called examples.php and contains the following code:

include (dirname(__FILE__) . "/adLDAP.php");
try {
    $adldap = new adLDAP();
}

The error that displays reads:

Fatal error: Class 'adLDAP' not found in /var/www/examples.php on line 14

Line 14 is:

$adldap = new adLDAP();

adLDAP.php is in the same folder as examples.php and contains the adLDAP class.

Have I messed up my include statement? I get "no such file or directory" with the other formats I have tried. Feels like I'm missing something obvious.

adLDAP.php instantiates the adLDAP class early on:

<?php
namespace adLDAP;

require_once(dirname(__FILE__) . '/collections/adLDAPCollection.php');
require_once(dirname(__FILE__) . '/classes/adLDAPGroups.php');
require_once(dirname(__FILE__) . '/classes/adLDAPUsers.php');
require_once(dirname(__FILE__) . '/classes/adLDAPFolders.php');
require_once(dirname(__FILE__) . '/classes/adLDAPUtils.php');
require_once(dirname(__FILE__) . '/classes/adLDAPContacts.php');
require_once(dirname(__FILE__) . '/classes/adLDAPExchange.php');
require_once(dirname(__FILE__) . '/classes/adLDAPComputers.php');

class adLDAP {

etc.


回答1:


adLDAP class definition is in adLDAP namespace. You need to tell PHP that this class is in this namespace:

$adldap = new adLDAP\adLDAP();

You can also import this class with use keyword:

<?php
    include (dirname(__FILE__) . "/adLDAP.php");
    use adLDAP\adLDAP;

    $adldap = new adLDAP;


来源:https://stackoverflow.com/questions/22262216/fatal-error-class-adldap-not-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!