Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.2.0

Bug #16491 delete of attributes in replace() method of Entry class
Submitted: 2009-08-04 03:49 UTC
From: hovenko Assigned: beni
Status: Closed Package: Net_LDAP2 (version 2.0.5)
PHP Version: 5.2.0 OS: Xandros Linux (Asus EEE)
Roadmaps: 2.1.0    
Subscription  


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 45 + 21 = ?

 
 [2009-08-04 03:49 UTC] hovenko (Knut-Olav Hoven)
Description: ------------ If trying to replace an attribute on an LDAP entry that gets a new value of 0 (the number zero), the attribute is deleted instead of updated. This is because of the way PHP handles "0" as equal to NULL when only using two equality characters (==) instead of three. Test script: --------------- $new = array( "description" => 0, ); $entry->replace($new); $entry->update(); Expected result: ---------------- The attribute should be updated with the new value of "0" instead of be deleted. Actual result: -------------- On a required attribute I get this error: Failed to update entry: Could not delete attribute description: Object class violation: LDAP_OBJECT_CLASS_VIOLATION

Comments

 [2009-08-04 03:50 UTC] hovenko (Knut-Olav Hoven)
The following patch has been added/updated: Patch Name: Net_LDAP2_Entry_replace Revision: 1249339855 URL: http://pear.php.net/bugs/patch-display.php?bug=16491&patch=Net_LDAP2_Entry_replace&revision=1249339855&display=1
 [2009-08-04 06:04 UTC] doconnor (Daniel O'Connor)
Can you expand your test script to be properly executable (ie, instantiate $entry for us)? Can you do a new version of your patch, it's backwards ! :D
 [2009-08-04 11:35 UTC] beni (Benedikt Hallinger)
-Assigned To: +Assigned To: beni -Roadmap Versions: +Roadmap Versions: 2.1.0
 [2009-08-04 11:58 UTC] beni (Benedikt Hallinger)
Thank you for your bugreport. The problem is, that the int 0 evaluates to both false and null, as you correctly described. When submitting "0", you should make sure, that you pass it as string, not as int, as LDAP attribute values are strings (at least, the description is). Conversion to the correct type is done on the LDAP server, so it is always safe to pass strings with numbers instead of real integers. Your patch could not be applied, because it imposes unknown results when for example true or false is passed. However, i introduced code into SVN which allows passing int(0); it gets converted to string("0") now. Try latest SVN or this: $new = array( "description" => "0", ); $entry->replace($new); $entry->update(); If the value is an variable, you can convert int to string: $string = "$int";
 [2009-08-04 12:00 UTC] beni (Benedikt Hallinger)
-Status: Assigned +Status: Closed
(fixed in svn)
 [2009-08-04 16:23 UTC] hovenko (Knut-Olav Hoven)
The following patch has been added/updated: Patch Name: Net_LDAP2_Entry_replace Revision: 1249384986 URL: http://pear.php.net/bugs/patch-display.php?bug=16491&patch=Net_LDAP2_Entry_replace&revision=1249384986&display=1
 [2009-08-04 16:31 UTC] hovenko (Knut-Olav Hoven)
@beni: I am unable to see why true or false might be a problem for applying the patch (which is now updated). If either true or false is set on an attribute, that is most likely, i believe, the value the user might expect to be updated on the entry as the string "1" or "". The documentation of the replace() method states this: "If the attribue value is null, the attribute will de deleted." I would expect any other value to be updated on the entry, even (bool)false.
 [2009-08-04 17:02 UTC] beni (Benedikt Hallinger)
The problem is, it is not defined. The doc says in the examples of the method documentation: "attr-name" => "single value", "attr-name" => array("multivalue1", "multivalue2") which references strigns. TRUE for example may update to string("true") or to boolean(true) or to int(1) - its not defined and may vary from server to server. Thats why it is left to you to properly call the method. Also note that phps ldap function ldap_modify() also expects it that way.