Bug #19503 [Opn->Ver]: Net_LDAP2_Entry getValue returns empty string when no attributes present

From: Date: Thu, 03 Jan 2013 08:12:41 +0000
Subject: Bug #19503 [Opn->Ver]: Net_LDAP2_Entry getValue returns empty string when no attributes present
References: 1  Groups: php.pear.bugs 
Request: Send a blank email to pear-bugs+get-9442@lists.php.net to get a copy of this message
Edit report at https://pear.php.net/bugs/bug.php?id=19503&edit=1 ID: 19503 Updated by: beni@php.net Reported By: pear dot php at feystorm dot net Summary: Net_LDAP2_Entry getValue returns empty string when no attributes present -Status: Open +Status: Verified Type: Bug Package: Net_LDAP2 Package Version: 2.0.12 PHP Version: 5.2.14 Roadmap Versions: New Comment: -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! Previous Comments: ------------------------------------------------------------------------ [2012-07-12 02:25:07] feystorm 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(). ------------------------------------------------------------------------ [2012-07-12 02:21:52] feystorm Added #patch bug:19503;patch:Net_LDAP2-get_value.patch;revision:1342056112;. ------------------------------------------------------------------------ [2012-07-11 22:19:07] feystorm 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') === ""; ------------------------------------------------------------------------ -- Edit this bug report at https://pear.php.net/bugs/bug.php?id=19503&edit=1

« previous php.pear.bugs (#9442) next »