Bug #79032 [Opn->Nab]: ldap_count_entries returns NULL not FALSE

From: Date: Wed, 25 Dec 2019 21:48:14 +0000
Subject: Bug #79032 [Opn->Nab]: ldap_count_entries returns NULL not FALSE
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224532@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79032&edit=1 ID: 79032 Updated by: requinix@php.net Reported by: admin at feministwiki dot org Summary: ldap_count_entries returns NULL not FALSE -Status: Open +Status: Not a bug Type: Bug Package: LDAP related Operating System: Ubuntu 16.04 LTS PHP Version: 7.4.1 Block user comment: N Private report: N New Comment: Returning NULL when the function is called incorrectly is consistent with the rest of PHP. https://www.php.net/manual/en/functions.internal.php > Note: If the parameters given to a function are not what it expects, such as passing an array > where a string is > expected, the return value of the function is undefined. In this case it will likely return > NULL but this is just > a convention, and cannot be relied upon. Besides that, any good IDE with PHP support should be able to detect when you forget a required function parameter, and if you still do so then PHP itself will give you an error message about it. Previous Comments: ------------------------------------------------------------------------ [2019-12-25 15:38:40] admin at feministwiki dot org Just a note: the expression 'cn=$newUsername' should of course be "cn=$newUsername" in my test script, although this makes no difference to the bug report. ------------------------------------------------------------------------ [2019-12-25 15:30:39] admin at feministwiki dot org Description: ------------ --- From manual page: https://php.net/function.ldap-count-entries --- When you forget to provide the first argument to ldap_count_entries (i.e. the link to the LDAP connection), it returns NULL instead of FALSE. As per documentation and consistency with other LDAP functions, it should return FALSE to indicate an error. Test script: --------------- $ldapLink = ldap_connect('localhost'); ldap_set_option($ldapLink, LDAP_OPT_PROTOCOL_VERSION, 3); $memberBase = "ou=members,dc=feministwiki,dc=org"; $userDN = "cn=testuser,$memberBase"; $newUsername = 'whatever'; ldap_bind($ldapLink, $userDN, '[REDACTED]'); $result = ldap_search($ldapLink, $memberBase, 'cn=$newUsername', array()); var_dump(ldap_count_entries($result)); # First argument missing. Expected result: ---------------- The function should return FALSE to indicate an error, as per documentation and consistency with other LDAP functions. Actual result: -------------- The function returns NULL. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79032&edit=1

« previous php.bugs (#224532) next »