PHPackages                             brannonh/php-debug - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. brannonh/php-debug

ActiveLibrary[Debugging &amp; Profiling](/categories/debugging)

brannonh/php-debug
==================

Simple debugging class for use in PHP scripts

1.0.0(5y ago)14MITPHPPHP &gt;=5.3.0

Since Oct 28Pushed 5y ago1 watchersCompare

[ Source](https://github.com/brannonh/php-debug)[ Packagist](https://packagist.org/packages/brannonh/php-debug)[ Docs](https://github.com/brannonh/php-debug)[ RSS](/packages/brannonh-php-debug/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

php-debug
=========

[](#php-debug)

php-debug is a simple debugging class for use in PHP scripts. Use it when you don't have access to a debugger, like in a customer's environment, or you need to gather complex and/or larger amounts of data that are not feasible to analyze in a debugging session.

Features
--------

[](#features)

- Encapsulate debugging values in a single variable, making it much easier to identify and remove debugging code later.
- Save complex data structures, utilizing arrays.
- Keep only a specific number of log entries (the most recent, defaults to 500) to avoid filling up disk space.
- Log data in JSON format.

Support
-------

[](#support)

This library has not been tested on PHP versions prior to 5.3.29. If you try it, please let us know how it goes by opening a new issue.

If you find problems on any other versions, please also let us know in a new issue.

Usage
-----

[](#usage)

To use php-debug, simply drop the `Debug.php` file somewhere in your source files and `include` or `require` it in the file that needs to be debugged. Then, create a new `Debug` object and use it to gather, save, and log data.

```
// Instantiate Debug.
$debug = new Debug;

// Save / modify data.
$debug->set('hello', 'world');
$debug->set('counter', 0);
$debug->increase('counter');
```

When logging, data is stored in as JSON at your file location of choice (by default, `debug.json` in the same directory as `Debug.php`).

```
// Save data to the log file.
$debug->log_data('hello');
$debug->log_data('counter');
```

API
---

[](#api)

The following API documentation is sorted alphabetically. To learn the basics and get started quickly, we recommend reading [\_\_construct](#__constructfilename-data-log_now-max_entries), [set](#setkey-data), [get](#getkey), [merge](#mergekey-data), [log\_data](#log_datakeys), and [log\_all](#log_all).

- [\_\_construct](#__constructfilename-data-log_now-max_entries)
- [count](#countkey)
- [decrease](#decreasekey-val)
- [get](#getkey)
- [increase](#increasekey-val)
- [is\_empty](#is_emptykey)
- [log\_all](#log_all)
- [log\_data](#log_datakeys)
- [log](#logdata)
- [merge](#mergekey-data)
- [set](#setkey-data)

### `__construct($filename, $data, $log_now, $max_entries)`

[](#__constructfilename-data-log_now-max_entries)

All the parameters of the constructor have default values, so none are necessary to get started with `Debug`. The `$data` parameter sets the internal data store and should always be an associative array. The behavior of `Debug` is undefined when `$data` is set to a scalar or an object.

#### Parameters

[](#parameters)

ParameterTypeRequiredDefaultNotes`$filename`string`'debug.json'`The default file is created in the same directory as `Debug.php`.`$data`array`array()`Use this to initialize the saved data.`$log_now`boolean`false`Log any initialized data immediately.`$max_entries`integer`500`The log file will be limited to this many entries (not lines).#### Returns

[](#returns)

TypeNotes`Debug`The `Debug` object[🎩](#api)

### `count($key)`

[](#countkey)

Count the number of values in the array or the number of characters in the string stored at `$key`.

#### Parameters

[](#parameters-1)

ParameterTypeRequiredDefaultNotes`$key`string✔️The key for the data element being counted#### Returns

[](#returns-1)

TypeNotesintegerThe number of elements in the array (using `count`) or string (using `strlen`)[🎩](#api)

### `is_empty($key)`

[](#is_emptykey)

Get the result of PHP's `empty()` function for the data element stored at `$key`.

#### Parameters

[](#parameters-2)

ParameterTypeRequiredDefaultNotes`$key`string✔️The key for the data element being checked#### Returns

[](#returns-2)

TypeNotesbooleanWhether or not the element is `empty`[🎩](#api)

### `decrease($key, $val)`

[](#decreasekey-val)

Perform `--` or `-=` operations on the data element stored at `$key`.

#### Parameters

[](#parameters-3)

ParameterTypeRequiredDefaultNotes`$key`string✔️The key for the data element being decreased`$val`integer`1`The value by which to decrease#### Returns

[](#returns-3)

TypeNotesvoid[🎩](#api)

### `get($key)`

[](#getkey)

Obtain the value of the data element stored at `$key`.

#### Parameters

[](#parameters-4)

ParameterTypeRequiredDefaultNotes`$key`string✔️The key for the data element being requested#### Returns

[](#returns-4)

TypeNotesmixedThe value of the requested data element[🎩](#api)

### `increase($key, $val)`

[](#increasekey-val)

Perform `++` or `+=` operations on the data element stored at `$key`.

#### Parameters

[](#parameters-5)

ParameterTypeRequiredDefaultNotes`$key`string✔️The key for the data element being increased`$val`integer`1`The value by which to increase#### Returns

[](#returns-5)

TypeNotesvoid[🎩](#api)

### `log_all()`

[](#log_all)

Write all stored data elements to the log file.

#### Parameters

[](#parameters-6)

ParameterTypeRequiredDefaultNotesvoid#### Returns

[](#returns-6)

TypeNotesvoid[🎩](#api)

### `log_data($keys)`

[](#log_datakeys)

Write the data elements stored at `$keys` to the log file.

#### Parameters

[](#parameters-7)

ParameterTypeRequiredDefaultNotes`$keys`string | array✔️The key(s) for the data element(s) being logged (can be a single key or multiple keys in an integer-indexed array )#### Returns

[](#returns-7)

TypeNotesvoid[🎩](#api)

### `log($data, $raw)`

[](#logdata-raw)

Write data directly to the log file without saving it as a data element.

[log\_all](#log_all) and [log\_data](#log_datakeys) interact with saved data elements, but this function skips that step for cases when you just want to log current values. `log_all` and `log_data` use this function internally.

#### Parameters

[](#parameters-8)

ParameterTypeRequiredDefaultNotes`$data`mixed✔️The data element to log (can be a single value or multiple values in an integer-indexed array )`$raw`boolean`true`Whether or not to treat `$data` as a single value and log it as-is

When this is `false`, `$data` is treated as if it had been saved with `set()`. When this is `true`, you cannot save multiple values in `$data`.#### Returns

[](#returns-8)

TypeNotesvoid[🎩](#api)

### `merge($key, $data)`

[](#mergekey-data)

Merge the `$data` array into the data element stored at `$key`. This is an easy way to update multiple values in a data element at once. Assumes `$key` references an array.

#### Parameters

[](#parameters-9)

ParameterTypeRequiredDefaultNotes`$key`string✔️The key for the data element being merged`$data`array✔️The data being merged into `$key`#### Returns

[](#returns-9)

TypeNotesvoid[🎩](#api)

### `set($key, $data)`

[](#setkey-data)

Save `$data` as the value of the data element stored at `$key`.

#### Parameters

[](#parameters-10)

ParameterTypeRequiredDefaultNotes`$key`string✔️The key for the data element being saved`$data`array✔️The data being saved into `$key`#### Returns

[](#returns-10)

TypeNotesvoid[🎩](#api)

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2025d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b4a39485005eabfa20719b35d8a1f6ddee64a6cad633f4bdb2401109892b4cfb?d=identicon)[brannonh](/maintainers/brannonh)

---

Top Contributors

[![brannonh](https://avatars.githubusercontent.com/u/15135353?v=4)](https://github.com/brannonh "brannonh (16 commits)")

---

Tags

debugdebugging

### Embed Badge

![Health badge](/badges/brannonh-php-debug/health.svg)

```
[![Health](https://phpackages.com/badges/brannonh-php-debug/health.svg)](https://phpackages.com/packages/brannonh-php-debug)
```

###  Alternatives

[spatie/global-ray

Enable Ray in all PHP files on your system

21863.0k1](/packages/spatie-global-ray)[mmucklo/krumo

KRUMO - version 2.0 of print\_r(); and var\_dump(); (with new updates)

89168.0k6](/packages/mmucklo-krumo)[xrdebug/php

PHP client library for xrDebug

23920.3k2](/packages/xrdebug-php)[jbzoo/jbdump

Script for debug and dump PHP variables and other stuff. This tool is a nice replacement for print\_r() and var\_dump() functions.

211.1M3](/packages/jbzoo-jbdump)[kktsvetkov/krumo

Krumo is a debugging tool, which displays structured information about any PHP variable. It is a nice replacement for print\_r() or var\_dump() which are used by a lot of PHP developers.

8260.7k](/packages/kktsvetkov-krumo)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
