[dev] is_a(), PEAR_Error and error mesages (newbie)
Dmitry Diskin
dda at ic.ru
Sun May 18 09:45:17 PDT 2003
Hello,
I'm trying to modify ldap auth driver to make it possible to delete
users from LDAP database. First of all, I set 'remove' capability to
'true' in horde/lib/Auth/ldap.php. Next, I created function removeUser:
function removeUser($userID)
{
$ldap = @ldap_connect($this->_params['hostspec']);
$binddn = $this->_params['uid'] . '=' .
$this->_params['username'] . ',' . $this->_params['basedn'];
$bind = @ldap_bind($ldap, $binddn, $this->_params['password']);
$dn = $this->_params['uid'] . '=' . $userID . ',' .
$this->_params['basedn'];
if (@ldap_delete($ldap, $dn)) {
return AUTH_OK;
} else {
Horde::logMessage('removeUser: ' . @ldap_error($ldap),
__FILE__, __LINE__, LOG_DEBUG);
$this->_setAuthError(_("Remove failed."));
return false;
}
}
And I'm keeping to receive "Successfully removed 'xxx' from the
system.", while actually remove does not work and in horde.log I can see
this:
May 18 20:26:57 HORDE [debug] [horde] removeUser: Insufficient access
[on line 176 of "/home/dda/horde/lib/Auth/ldap.php"]
According to the following code in horde/admin/user.php:
if (is_a($auth->removeUser($f_user_name), 'PEAR_Error')) {
$notification->push(sprintf(_("There was a problem removing
'%s' from the system."), $f_user_name), 'horde.error');
} else {
$notification->push(sprintf(_("Successfully removed '%s'
from the system."), $f_user_name), 'horde.success');
}
I should receive '..was a problem..' message if removeUser() returns
value of 'PEAR_Error' class. I used as an example function
_authenticate($userID, $credentials) - comments to this function say:
"@return boolean True on success or a PEAR_Error object on failure."
Please explain the following piece of code:
$ldap = @ldap_connect($this->_params['hostspec']);
if (!$ldap) {
$this->_setAuthError(_("Failed to connect to LDAP server."));
return false;
}
I'm new to PHP, and I can't understand, first of all, how "return
false;" can represent a PEAR_Error object.
Thank you for your help.
Dmitry.
More information about the dev
mailing list