Bug #79165 [Nab]: trying to access ldap_get_entries array triggers: Trying to access array offset

From: Date: Thu, 12 Mar 2020 18:25:34 +0000
Subject: Bug #79165 [Nab]: trying to access ldap_get_entries array triggers: Trying to access array offset
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226071@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79165&edit=1

 ID:                 79165
 User updated by:    mbiebl at messageconcept dot com
 Reported by:        mbiebl at messageconcept dot com
 Summary:            trying to access ldap_get_entries array triggers:
                     Trying to access array offset
 Status:             Not a bug
 Type:               Bug
 Package:            LDAP related
 PHP Version:        7.4.2
 Block user comment: N
 Private report:     N

 New Comment:

@nikic: I wonder, should the example at https://www.php.net/manual/en/ldap.examples-controls.php
be updated accordingly?

E.g. Example #5 uses

    $entries = ldap_get_entries($link, $result);
    foreach ($entries as $entry) {
        echo "cn: ".$entry['cn'][0]."\n";
    }

With PHP 7.4 this will now trigger the aforementioned notice afaics.


Previous Comments:
------------------------------------------------------------------------
[2020-01-24 21:29:44] mbiebl at messageconcept dot com

Let's close this. This is an issue that needs to be solved in our code.
The issue was just hidden with previous PHP releases. We need to handle the 'count' array
entry explicitly.
Not sure yet, if array_slice() is the proper solution. I guess there is no guarantee that the
'count' entry will always be the first entry in the result array.

------------------------------------------------------------------------
[2020-01-24 13:12:28] mbiebl at messageconcept dot com

$result = ldap_search($con, $dn, $filter, $justthese);
$entries = ldap_get_entries($con, $result);

foreach ($entries as $e) {
    if ($e[$this->uidNameAttribute][0] == '') {
        continue;
    }
    $principal = array('uri' => 'principals/' .
strtolower($e[$this->uidNameAttribute][0]),);
    foreach ($this->fieldMap as $key => $value) {
        if (isset($e[$value['ldapProperty']])) {
            $principal[$key] = $e[$value['ldapProperty']][0];
        }
    }
    $principals[] = $principal;
}

------------------------------------------------------------------------
[2020-01-24 13:07:39] cmb@php.net

Could you please post the relevant code (and show the reported
line number)?

------------------------------------------------------------------------
[2020-01-24 12:28:07] mbiebl at messageconcept dot com

Hm, right. I guess I need to explicitly skip the "count" element now which is part of the
$result array.

foreach (array_slice($entries, 1) as $e) { .. }

appears to work. Not sure if this is the cleanest solution though. WDYT?

------------------------------------------------------------------------
[2020-01-24 12:05:41] nikic@php.net

foreach does not trigger this notice. Please check the reported line number carefully. It must
involve something like "$array[$offset]".

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=79165


--
Edit this bug report at https://bugs.php.net/bug.php?id=79165&edit=1


Thread (8 messages)

« previous php.bugs (#226071) next »