|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1230 dbmnextkey misbehaves
Submitted: 1999-03-12 16:51 UTC Modified: 1999-03-13 08:31 UTC
From: eric at ipass dot net Assigned:
Status: Closed Package: DBM/DBA related
PHP Version: 3.0.6 OS: Solaris 2.5.1
Private report: No CVE-ID: None
 [1999-03-12 16:51 UTC] eric at ipass dot net
It appears that dbmnextkey returns the next key in a dbm file since the last call to dbmnextkey.  Successive calls to dbmnextkey() using the same key value will return different values.  Unless i'm not reading the docs right, dbmnextkey() should return the key after the key passed to it.  So:

echo dbmnextkey($dbm_id, "mykey") . "\n";
echo dbmnextkey($dbm_id, "mykey") . "\n";
echo dbmnextkey($dbm_id, "mykey") . "\n";

... should always echo the same value.  And:

  $dbm_id = dbmopen("anydbm", "w");
  $firstkey = dbmfirstkey($dbm_id);
  $key = $firstkey;
  while ($key) {
    echo "$key = " . dbmfetch($dbm_id, $key) . "\n";
    $key = dbmnextkey($dbm_id, $firstkey);

... should be an infinite loop.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [1999-03-13 08:31 UTC] sas
The exact behaviour depends on the underlying implementation scheme. You are only guaranteed that

$key = dbmfirstkey($id);
while($key) {
	$nextkey = dbmnextkey($id, $key);
	$key = $nextkey;

will visit all items in the database.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat Jul 02 14:04:40 2022 UTC