Search code examples
phpadldap

Fatal error: Class 'adLDAP' not found


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.


Solution

  • 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;