php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50185 ldap_get_entries() return false instead of an empty array when there is no error
Submitted: 2009-11-16 08:50 UTC Modified: 2009-11-18 17:45 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: Joel dot Brogniart at univ-lyon2 dot fr Assigned:
Status: Closed Package: LDAP related
PHP Version: 5.2.11 OS: Mac OS X 10.5.8
Private report: No CVE-ID: None
 [2009-11-16 08:50 UTC] Joel dot Brogniart at univ-lyon2 dot fr
Description:
------------
With PHP version < 5.2.10, if the "bad_uid" is not in the LDAP directory and no error occured the following code return an empty array in $info. With PHP version 5.2.10 it return FALSE $info even when there is no error.

(simplified code)

$ldap_host="ldap.example.com";
$ldap_root="ou=people,dc=example,dc=com";
$ldap_dn="cn=admin,ou=people,dc=example,dc=com";
$ldap_password="fak3pwd";
$result = array();
$attribute_list = array("uid");
$connection = ldap_connect($ldap_host);
$link = @ldap_bind($connection, $ldap_dn, $ldap_password);
$search="(uid=bad_uid)";
$search_result = ldap_search($connection, $ldap_root, $search, $attribute_list);
$info = ldap_get_entries($connection, $search_result);


Reproduce code:
---------------
---
From manual page: function.ldap-get-entries#Return Values
---

$ldap_host="ldap.example.com";
$ldap_root="ou=people,dc=example,dc=com";
$ldap_dn="cn=admin,ou=people,dc=example,dc=com";
$ldap_password="fak3pwd";
$result = array();
$attribute_list = array("uid");
$connection = ldap_connect($ldap_host);
$link = @ldap_bind($connection, $ldap_dn, $ldap_password);
$search="(uid=bad_uid)";
$search_result = ldap_search($connection, $ldap_root, $search, $attribute_list);
$info = ldap_get_entries($connection, $search_result);


Expected result:
----------------
$info :
Array
(
)


Actual result:
--------------
$info :

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-16 09:38 UTC] jani@php.net
RTFM: "Returns a complete result information in a multi-dimensional array on success and FALSE on error. "

Your query most likely has an error, try check it with ldap_error()
 [2009-11-17 04:40 UTC] php at group dot apple dot com
This behavior changed in 5.2.9, apparently due to the change associated 
with http://bugs.php.net/bug.php?id=48469
 [2009-11-17 05:27 UTC] Joel dot Brogniart at univ-lyon2 dot fr
I confirm (and as stated in my description) that ldap-get-entries return NULL when there is no entries corresponding to the request filter even when there is no error. No error. And I too think that the new behavior comes from the change described at http://bugs.php.net/bug.php?id=48469.
 [2009-11-17 09:20 UTC] jani@php.net
I'd be quite surprised if this func returned null in PHP 5.2.11 since there's only code to return FALSE. var_dump($info); to see what it is.
 [2009-11-18 06:55 UTC] Joel dot Brogniart at univ-lyon2 dot fr
Here is a transcript of an interactive PHP session (real user, server, password modified).

server:~ johndoe$ php -v
PHP 5.2.11 (cli) (built: Sep 28 2009 16:48:57) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
server:~ johndoe$ php -a
Interactive mode enabled

<?php
$ldap_host="ldap.example.com";
$ldap_root="ou=people,dc=example,dc=com";
$ldap_dn="cn=admin,ou=people,dc=example,dc=com";
$ldap_password="fak3pwd";
$attribute_list = array("uid");
$connection = ldap_connect($ldap_host);
printf("ldap_connect error:%s\n", ldap_errno($connection));
$link = @ldap_bind($connection, $ldap_dn, $ldap_password);
printf("ldap_bind error:%s\n", ldap_errno($connection));
$search="(uid=bad_uid)";
$search_result = ldap_search($connection, $ldap_root, $search,
$attribute_list);
printf("ldap_search error:%s\n", ldap_errno($connection));
$info = ldap_get_entries($connection, $search_result);
printf("ldap_get_entries error:%s\n", ldap_errno($connection));
printf("var_dump($info): ");
var_dump($info);
?>
ldap_connect error:0
ldap_bind error:0
ldap_search error:0
ldap_get_entries error:0
var_dump(): NULL
 [2009-11-18 17:44 UTC] svn@php.net
Automatic comment from SVN on behalf of jani
Revision: http://svn.php.net/viewvc/?view=revision&revision=290923
Log: - Fixed bug #50185 (ldap_get_entries() return false instead of an empty array when there is no error).
# This is also revert of bad patch to bug #48469 and fixes it properly.
 [2009-12-24 02:08 UTC] svn@php.net
Automatic comment from SVN on behalf of srinatar
Revision: http://svn.php.net/viewvc/?view=revision&revision=292574
Log: - Update tests to reflect current behavior after fix for bug #50185
 [2010-01-25 14:07 UTC] svn@php.net
Automatic comment from SVN on behalf of johannes
Revision: http://svn.php.net/viewvc/?view=revision&revision=293981
Log: merge -r292574: - Update tests to reflect current behavior after fix for bug
#50185 (srinatar)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 07:01:29 2024 UTC