From:             marc-bennewitz at arcor dot de
Operating system: openSUSE 11.3 (x86_64)
PHP version:      5.4.4
Package:          DBM/DBA related
Bug Type:         Bug
Bug description:Iterating over items + dba_delete not working

Description:
------------
With some handlers it's not possible to iterate over items if there will be
items deleted within iteration.

Test script:
---------------
// Script to delete items with specific prefix

$dba = dba_open(sys_get_temp_dir() . DIRECTORY_SEPARATOR .
uniqid('zfcache_dba_'), 'c', 'qdbm');

dba_insert('key1', 'value', $dba);
dba_insert('test2', 'value', $dba);
dba_insert('key3', 'value', $dba);
dba_insert('test4', 'value', $dba);
dba_insert('key5', 'value', $dba);

$key = dba_firstkey($dba);
var_dump($key);
while ($key !== false) {
    $key = dba_nextkey($dba);
    var_dump($key);
}

echo '#############################' . PHP_EOL;

$key = dba_firstkey($dba);
while ($key !== false) {
    if (substr($key, 0, 3) === 'key') {
        var_dump($key);
        dba_delete($key, $dba);
    }
    $key = dba_nextkey($dba);
}

echo '#############################' . PHP_EOL;

$key = dba_firstkey($dba);
var_dump($key);
while ($key !== false) {
    $key = dba_nextkey($dba);
    var_dump($key);
}


Expected result:
----------------
string(4) "key1"
string(5) "test2"
string(4) "key3"
string(5) "test4"
string(4) "key5"
bool(false)
#############################
string(4) "key1"
string(4) "key3"
string(4) "key5"
#############################
string(5) "test2"
string(5) "test4"
bool(false)

Actual result:
--------------
flatfile -> correct
inifile  -> wrong (breaks iteration after first delete)
gdbm     -> wrong (breaks iteration after first delete)
qdbm     -> correct
db4      -> correct

-- 
Edit bug report at https://bugs.php.net/bug.php?id=62491&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=62491&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=62491&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=62491&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=62491&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=62491&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=62491&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=62491&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=62491&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=62491&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=62491&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=62491&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=62491&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=62491&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=62491&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=62491&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=62491&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=62491&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=62491&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=62491&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=62491&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=62491&r=mysqlcfg

Reply via email to