php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79032 ldap_count_entries returns NULL not FALSE
Submitted: 2019-12-25 15:30 UTC Modified: 2019-12-25 21:48 UTC
From: admin at feministwiki dot org Assigned:
Status: Not a bug Package: LDAP related
PHP Version: 7.4.1 OS: Ubuntu 16.04 LTS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: admin at feministwiki dot org
New email:
PHP Version: OS:

 

 [2019-12-25 15:30 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-12-25 15:38 UTC] 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 21:48 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2019-12-25 21:48 UTC] requinix@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 19:01:32 2024 UTC