php / php/php-src

dba_insert() for ini files can result in duplicate keys

Open
#10,891 4 comments 0 reactions 1 assignee View on GitHub

@Girgias is already working on this.

Since Mar 21, 2023.

Bug Extension: dba Status: Verified
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The following code:

<?php

@unlink("test.ini");
touch("test.ini");
$db = dba_open("test.ini", "wl", "inifile");
var_dump($db);

var_dump(dba_fetch("nonexisting", $db));
var_dump(dba_insert("nonexisting", "newvalue", $db));
var_dump(dba_insert("nonexisting", "newvalue", $db));

dba_close($db);

Resulted in this output:

resource(7) of type (dba)
bool(false)
bool(true)
bool(true)

But I expected this output instead:

resource(7) of type (dba)
bool(false)
bool(true)
bool(false)

And additionally: not an extra same-key entry in my ini file.
Because according to the docs at https://www.php.net/manual/en/function.dba-insert.php:

If this key already exist in the database, this function will fail.

PHP Version

PHP 8.1+

Operating System

Linux 6.2.x

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.