mapik / dbase
A pure PHP implementation of the dBase functions, standing in for ext-dbase where it cannot be installed
Requires
- php: >=8.1
Requires (Dev)
- phpstan/phpstan: ^2.2
- phpstan/phpstan-phpunit: ^2.0
- phpunit/phpunit: ^10.5 || ^11.0 || ^12.0
- squizlabs/php_codesniffer: ^4.0
Suggests
- ext-dbase: The extension itself is faster. This package steps aside when it is loaded.
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-12 13:53:20 UTC
README
A pure PHP implementation of the dBase functions, for where ext-dbase cannot be installed.
The extension is a PECL build with no package on most distributions, so an application that reads
or writes DBF files has to either compile it or go without. This stands in for it: require the
package and keep calling dbase_open(), dbase_create() and the rest, whichever of the two is
actually there.
composer require mapik/dbase
The global functions are defined only when the extension is missing, so nothing changes for an installation that has it.
Two files, and the split is the point:
dbase.inc.phpis autoloaded on every request and holds nothing but the constants and the twelve function definitions.src/DBase.phpholds the work, and the autoloader fetches it the first time one of those functions is called. Where the extension is installed that never happens at all.
The class can also be used directly as Mapik\DBase\DBase, which is what lets the two
implementations be held against each other in the tests. It carries a namespace where the original
did not: a global DBase is a name anything could claim, and two packages claiming it would fight
over which one the autoloader hands out. The functions stay global, because being callable under
their own names is the whole point of the package.
What it matches
Byte for byte with the extension, proven by the test suite rather than by reading the manual:
- the header, the field descriptors, the record area and the
0x1Aend of file marker - how a value becomes characters, which is the part that is easy to get wrong. The extension
goes by the type of what it is handed and not by the field, so a float is written to the field's
decimals and an integer is not:
0and0.0in anN,8,2field come out as0and0.00. Strings pass through untouched. - what comes back out: a number with decimals is a float and one without is an integer, text keeps
the spaces it is stored with, and
deletedsits after the fields rather than before them
dbase_get_header_info() returns the same six keys the extension does, format included.
Requirements
PHP 8.1 or newer. No dependencies.
Development
docker compose -f docker-compose.dev.yml up -d
docker compose -f docker-compose.dev.yml exec dev composer check
composer check is the suite, PSR-12 and PHPStan at level 8. composer cs-fix puts right what
the coding standard can put right by itself.
The image is plain PHP with the extension built in. There is no web server because there is nothing to serve - and the extension is there on purpose, because the parity tests are the ones worth running and they skip themselves where there is nothing to compare against.
Credit
A fork of donfbecker/dbase, which is where the original implementation and the MIT licence come from.