Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8004115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:49:50+00:00 2026-06-04T16:49:50+00:00

I can’t use a PEAR library when I have my custom namespace declared. The

  • 0

I can’t use a PEAR library when I have my custom namespace declared.

The namespace and the autoload function:

<?php
namespace ldapwrangler;
function autoload($class_name)
{
  $path = ROOT_DIR . "/inc/" . str_replace('\\', "/", $class_name) . ".class.php";    
  require_once($path);
}
spl_autoload_register('ldapwrangler\autoload');
?>

If I try something like this ROOT_DIR/inc/ldapwrangler/LDAP.class.php:

<?php
namespace ldapwrangler;
require_once 'Net/LDAP2.php';

class LDAP{
    protected $connection;
    protected $defaultSearchBase;

    /**
     * @param $conf conf array containing ldap direction login and server.
     */
    function __construct($conf)
    {
        $this->connection = $this->set_connection($conf);
        $this->defaultSearchBase = $conf['basedn'];
    }
    /**
     * Bind to the directory configured in the $conf array
     * 
     * @param $conf conf array containing ldap direction login and server.
     */ 
    function set_connection($conf)
    {
        $ldap = Net_LDAP2::connect($conf);

        // Testing for connection error
        if (PEAR::isError($ldap)) {
            $msg = 'Could not connect to LDAP server: '.$ldap->getMessage();
            Logging::log_message('error',$msg);
            return false;
        }
        return $ldap;
    }

    //rest of the class...
    }
?>

I get an error like this:

May 29 10:03:32 reagand-desktop apache2: PHP Fatal error: require_once(): Failed opening required ‘/home/reagand/dev/ldap_wrangler/inc/ldapwrangler/Net_LDAP2.class.php’ (include_path=’.:/usr/share/php:/usr/share/pear’) in /home/reagand/dev/ldap_wrangler/config.php on line 18

FYI, line 18 is the require_once() part of the autoload function.

How to I tell php to not use the ldapwrangler namespace for the Net_LDAP2 classes? Or any other non-ldapwrangler classes, for that matter.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:49:52+00:00Added an answer on June 4, 2026 at 4:49 pm

    Declare you’re using an external namespace:

    <?php
    
    namespace ldapwrangler;
    use Net_LDAP2;
    require_once 'Net/LDAP2.php';
    

    Every class outside the declared namespace needs to be declared by the use keyword.

    Please also take a look at PSR-0, a standard for these kind of things like namespace usage.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone explain me what's going on? I use this method - (BOOL)shouldAutorotateToInterfaceOrientation:( UIInterfaceOrientation)interfaceOrientation
Can anyone please advice how can I have value of i in the following
I have a jquery bug and I've been looking for hours now, I can't
Can PHP PDO extension bind nested objects automatically ? I mean using foreign key
Can someone guide me on a possible solution? I don't want to use /bin/cp
Can't figure out how to do this in a pretty way : I have
Can a Visual Studio 2008 custom tool be passed additional parameters from the custom
Can i use a Select within a concat in xslt? eg <xsl:for-each select=root/OrderItems/lineitem> <xsl:element
Can you have submenus with the top level set to checkable in WPF? I
Can we use the asterisk character * for a search action in SQL database?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.