php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62492 dba_firstkey & dba_nextkey retuns NULL (instead false) on invalid dba resource
Submitted: 2012-07-06 09:08 UTC Modified: 2013-12-03 14:44 UTC
From: marc-bennewitz at arcor dot de Assigned:
Status: Not a bug Package: DBM/DBA related
PHP Version: 5.4.4 OS: openSUSE 11.3 (x86_64)
Private report: No CVE-ID:
 [2012-07-06 09:08 UTC] marc-bennewitz at arcor dot de
Description:
------------
The functions "dba_firstkey" & "dba_nextkey" retuns NULL (instead of false) on invalid dba resource.
It's documented as "Returns the key on success or FALSE on failure."
That can result in an infinite loop on iterate over items.

Test script:
---------------
$dba = false;

var_dump(dba_firstkey($dba));
var_dump(dba_nextkey($dba));

Expected result:
----------------
PHP Warning:  dba_firstkey() expects parameter 1 to be resource, boolean given in /tmp/dba_firstkey_nextkey.php on line 5

Warning: dba_firstkey() expects parameter 1 to be resource, boolean given in /tmp/dba_firstkey_nextkey.php on line 5
boolean(false)
PHP Warning:  dba_nextkey() expects parameter 1 to be resource, boolean given in /tmp/dba_firstkey_nextkey.php on line 6

Warning: dba_nextkey() expects parameter 1 to be resource, boolean given in /tmp/dba_firstkey_nextkey.php on line 6
boolean(false)

Actual result:
--------------
PHP Warning:  dba_firstkey() expects parameter 1 to be resource, boolean given in /tmp/dba_firstkey_nextkey.php on line 5

Warning: dba_firstkey() expects parameter 1 to be resource, boolean given in /tmp/dba_firstkey_nextkey.php on line 5
NULL
PHP Warning:  dba_nextkey() expects parameter 1 to be resource, boolean given in /tmp/dba_firstkey_nextkey.php on line 6

Warning: dba_nextkey() expects parameter 1 to be resource, boolean given in /tmp/dba_firstkey_nextkey.php on line 6
NULL

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-03 14:44 UTC] mike@php.net
-Status: Open +Status: Not a bug
 [2013-12-03 14:44 UTC] mike@php.net
It's convention that functions return NULL on invalid arguments.

See the note here: http://php.net/manual/en/functions.internal.php
 
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Fri Sep 04 10:01:36 2015 UTC