0

So I have the following code:

try {
    if ($connectionid = ldap_connect($ldapserver)) {    
        $ldapbindid=ldap_bind($connectionid, $binddn, $bindpw);
        if ($mysearch = ldap_search($connectionid, $basedn, $query)) {
            //more LDAP code here
        }
    } else {
        return false;
    }
} catch (Exception $exception) {
    return false;
}

But because I'm supplying the wrong binddn and password, I'm getting a PHP error in the ldap_bind command.

Warning: ldap_bind(): Unable to bind to server: Invalid credentials

But reading my code, I understand I should get a boolean instead?

I have the impression that any errors that happens within the confines of the "try" section is going to be handled by the "catch" section. perhaps I'm understanding try/catch incorrectly?

Thanks a lot

mrjayviper
  • 2,258
  • 11
  • 46
  • 82
  • 1
    Your error is a PHP warning, which is not catchable. Only instances of `Exception` can be caught. – scrowler Jul 25 '16 at 03:23
  • Maybe [this](http://stackoverflow.com/questions/1241728/can-i-try-catch-a-warning) will help if you want to be able to "catch" the warning. – segFault Jul 25 '16 at 03:24

0 Answers0