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

Bug #19503 Net_LDAP2_Entry getValue returns empty string when no attributes present
Submitted: 2012-07-12 02:19 UTC
From: feystorm Assigned: beni
Status: Closed Package: Net_LDAP2 (version 2.0.12)
PHP Version: 5.2.14 OS:
Roadmaps: 2.1.0    
Subscription  


 [2012-07-12 02:19 UTC] feystorm (Patrick Hemmer)
Description: ------------ When performing getValue for an attribute which does not exist, the return value is an empty string (in the case of $option = 'single') or an array with a single element of an empty string (in the case of $option = 'all'). This is bad behavior for a few reasons. 1) it complicates being able to do foreach loops over the return value as now you have to test for an empty string 2) some LDAP servers can return an empty string as an attribute value which makes it impossible to tell the difference between no values, and an empty value (without having to call the `exists` function) 3) Net_LDAP2 is supposed to be a port with similar behavior to perl's Net::LDAP, this is not how Net::LDAP behaves In the case of $option = 'all', it should either return an empty array, `false`, or `null` For $option = 'single' it should return `false` or `null`. Expected result: ---------------- # for an entry which has no `foo` attribute: $entry->getValue('foo', 'all') === array(); $entry->getValue('foo', 'single') === false; Actual result: -------------- # for an entry which has no `foo` attribute: $entry->getValue('foo', 'all') === array(""); $entry->getValue('foo', 'single') === "";

Comments

 [2012-07-12 06:21 UTC] feystorm (Patrick Hemmer)
 [2012-07-12 06:25 UTC] feystorm (Patrick Hemmer)
I've attached a patch which fixes the issue. It also changes the behavior of the getValue() function to not shift the value off the internal values array. This is just to make the behavior consistent with perl's Net::LDAP as it doesn't do that. It's also arguably good behavior as subsequent calls to getValue should return the same data. It should be called `shiftValue` if it's going to shift().
 [2013-01-03 13:12 UTC] beni (Benedikt Hallinger)
-Status: Open +Status: Verified
Hello, thank you for the contribution. Of course you are right and i will incorporate your patch soon. Thank you very much for providing code!
 [2013-01-03 13:32 UTC] beni (Benedikt Hallinger)
-Status: Verified +Status: Closed -Assigned To: +Assigned To: beni -Roadmap Versions: +Roadmap Versions: 2.1.0
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.