PHPackages                             evo/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. evo/debug

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

evo/debug
=========

Debugger(circular safe printer)

2.2.0(1y ago)17121GPL-3.0PHPPHP &gt;=8.3

Since Apr 5Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ArtisticPhoenix/Debug)[ Packagist](https://packagist.org/packages/evo/debug)[ RSS](/packages/evo-debug/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (8)Dependencies (1)Versions (12)Used By (1)

Debug for PHP
=============

[](#debug-for-php)

This is a fully featured debug output/print class, it's main features are

- Adjustable visibility, print public/protected/private properties, constants etc.
- Adjustable depth limits, limit how deep the debugger looks in nested data
- Circular reference safe (e.g. an object references itself)
- Auto back tracing, prints the file and line where the debugging function was called from
- Debug/exit
- Debug/output buffering
- Stack tracing
- can be called from included functions
- overall better formating, similar to `var_dump`

### Class reference

[](#class-reference)

```
    //construct or get an instance of Debug
    public static function getInstance(string $alias=''): self;
    //check if a given alias is instantiated
    public static function isInstantiated(string $alias=''): bool
    //register the procedural function
    public static function regesterFunctions(): void;
    //check if HTML mode is on
    public function getHtmlOutput(): bool;
    //change output to HTML mode [default is false]
    public function setHtmlOutput(bool $htmlOutput): void;
    //get the depth limit
    public function getDepthLimit(): int;
    //set the depth limit (how deep to dig into nested arrays and objects)
    public function setDepthLimit(int $depthLimit): void;
    //get the flags that are set
    public function getFlags(): int;
    //set flags
    public function setFlags(int $flags): void;
    //check if a flag is set
    public function hasFlag(int $flag): bool;
    //Debug and output
    public function dump(mixed $input=null, int $offset = 0): void;
    //Debug and output
    public function dumpException(Throwable $exception, int $offset = 0): void;
    //Debug and output
    public function dumpSql(string $statement, array $params=[], int $offset = 0): void;
    //Debug and return
    public function export(mixed $input=null, $offset = 0): string;
    //Start debugging output buffer, output will be capture until flush or end is called
    public function start(int $offset=0): void;
    //End debugging output buffer, and return it
    public function flush(int $offset=0): void;
    //End debugging output buffer, and output it
    public function end(int $offset=0): string;
    //Kill PHP execution with a message and a
    public function kill(mixed $input=null, $offset=0): void;
    //debug without the outer formatting, output it
    public function varDump(mixed $input);
    //debug without the outer formatting, return it
    public function varExport(mixed $input, int $level=0, array $objInstances=array()): string;
    //return the part of the backtrace where this function was called from
    public function trace(int $offset=0): array;
    //print a backtrace - formatted like a stacktrace
    public function backTrace(int $offset=0): void;
    //return a backTrace
    public function getTraceFirst(int $offset=0): arrat;
    //return the formatted trace of getTraceFirst.
    public function getTraceFirstAsString(int $offset=0): string;
```

### Properties

[](#properties)

NameTypeRequiredDescription$aliasstringnoname of a given instance of Debug$htmlOutputbooleannoSwitch between HTML and Text output$depthLimitintegernoMax nesting level to output$flagsbitwisenoOptions - see Flags$inputmixedyesInput to process (variables to debug)$offsetintegernoManual Offset for backtracking (backtrace where debug was called from). Backtracking should be done automatically, but it may fail in some "edge" cases. This allows you to manually set the offset (see function calls for example)$levelintegernocurrent depth level (internal use)$objInstancesarraynotracking array for object instance (internal use)### Object Flags

[](#object-flags)

NameDescriptionSHOW\_CONSTANTSInclude object constants in outputSHOW\_PUBLICInclude public properties in outputSHOW\_PROTECTEDInclude protected properties in outputSHOW\_PRIVATEInclude private properties in outputSHOW\_ACCESSIBLEInclude constants and public properties in outputSHOW\_VISIBLEInclude constants and public properties and protected properties in outputSHOW\_ALLInclude all of the above in outputFlags are bitwise and can be set like this `SHOW_CONSTANTS | SHOW_PUBLIC` the same way PHP constants for various things are handled. The default is `SHOW_ALL`

The debugger can handle any type provided by PHP's `gettype()`.

- boolean
- integer
- double
- string
- resource
- NULL
- array
- object
- unknown type

These are output in a format much like PHP's built in `var_dump` as I find that the most useful format. When in HTML output mode, debug is still returned as a string. It has a set of `` tags added in to preserve whitespace and string variables are ran though `htmlspecialchars($input, ENT_NOQUOTES, 'UTF-8', false)` as to not inject the debug data as HTML into the page.

It is circular reference safe, unlike many of PHP's built-in output function. A simple example of a circular reference is an object that stores a reference to itself in one of its properties. Another example is an object that stores a reference to a second object that stores a reference to the first object. In PHP's built-in functions, this results in infinite recursion. The Debugger instead replaces the circular reference with a simple placeholder `~CIRCULAR_REFRENCE~`.

Similarly, it also has protection or limits on the depth it will look at when outputting. This limit can be set in the constructor. Once the depth limit is reached a placeholder will be substituted `~DEPTH_LIMIT~`.

### Example

[](#example)

```
================================= evo\debug\Debug::dump ==================================
Output from FILE[ {yourpath}\index.php ] on LINE[ 25 ]
------------------------------------------------------------------------------------------
object(DebugTestItem)#0 (10) {
        ["CONSTANT":constant] => string(8) "constant",
        ["PUB_STATIC":public private] => string(10) "pub_static",
        ["PRO_STATIC":protected private] => string(10) "pro_static",
        ["PRI_STATIC":private private] => string(10) "pri_static",
        ["pub":public] => string(3) "pub",
        ["pro":protected] => string(3) "pro",
        ["pri":private] => string(3) "pri",
        ["array":public] => array(3){
                [0] => int(0),
                ["one"] => int(1),
                ["array"] => array(3){
                        [0] => string(3) "two",
                        [1] => string(5) "three",
                        [2] => string(4) "four",
                },
        },
        ["object":protected] => object(stdClass)#0 (0) {},
        ["self":private] => object(DebugTestItem)#0 (0) {~CIRCULAR_REFERENCE~},
}
==========================================================================================
```

Please note that `{yourpath}` will be the actual path to the index file on your system. This is useful if you are like me and forget where you put all your print function.

Debug is a Multiton, or a collection wrapper for singletons. This means you cannot construct this class manually. To construct it call `$D = Debug::getInstance('alias')`.

For ease of access you can use the procedural functions after calling `Debug::regesterFunctions()`. The procedural function area all named `debug_{methodname}`. So for example you can call `$Debug->dump()` with the function `debug_dump()`. You can access the function instance by using the `Debug::ALIAS_FUNCTIONS` constant, such as `$instance = Debug::getInstance(Debug::ALIAS_FUNCTIONS)`. One would do this, for example, to change the output from text to HTML or to change the visibility flags. Then the functions will use this instance and any custom settings you make to it.

An example of Manual offset is in the debug functions

**index.php**

```
//require composer PSR4 autoloader
require_once 'vendor/autoload.php';
//regester the procedural functions for debug
Debug::regesterFunctions();
//example of modifying the depth limit for the instance used in the procedural functions
Debug::getInstance(Debug::ALIAS_FUNCTIONS)->setDepthLimit(4);

debug_dump("foo"); //we'll say this is line 8 of index.php
```

**src/functions.php**

```
if (!function_exists('debug_dump')) {
    /**
     *
     * {@inheritDoc}
     * @see \evo\debug\Debug::dump()
     */
    function debug_dump($input, $offset=1)
    {
        Debug::getInstance(Debug::ALIAS_FUNCTIONS)->dump($input, $offset); //this is line 20 of functions.php
    }
}
```

**src/Debug.php**

```
public function dump($input, $offset = 0)
{
  ...
}
```

As you can see the `$offset=1` for `debug_dump()` has a default of **1**, this is set to 0 in the class itself. The reason for this (and for having a manual offset) is because we are wrapping the method call in a function. If we didn't modify the offset Debug would return the location it was called which is in the **src/functions.php** file on like 20. This is not what we want, we actually want where the `debug_dump` function was called from, in this example line 8 from **index.php**. There is no way to know this is the intention from inside the **Debug** class when it builds the back trace. Because it's 1 call away from the actual class call, we set it as 1. Then Debug knows to shift the backtrace by that offset so that it displays the correct file and line number that we actually want.

### Installation

[](#installation)

The prefer way to install is to include it in you composer.json file as this project depends on another one of my projects named [Pattern](https://github.com/ArtisticPhoenix/Pattern). So if you just download it directly it won't have that dependency unless you run the composer file included in the project.

```
{
   "require" : {
		"evo/debug" : "~ 2.0"
	}
}

```

### Release Notes

[](#release-notes)

- 1.0.0 - init release
- 1.0.1 - added procedural functions
- 1.0.3 - shortened function names
- 2.0.0 - PHP 8 compatibility
- 2.1.0 - added method dumpException
- 2.2.0 - added method dumpSql, added support for Enum, Final, Readonly and Abstract objects

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance48

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity85

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 74.6% 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

Every ~257 days

Recently: every ~603 days

Total

11

Last Release

393d ago

Major Versions

1.0.6 → 2.0.02024-09-10

PHP version history (2 changes)1.0.0PHP &gt;=5.6

2.0.0PHP &gt;=8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/73ff70bb5a9ec9b1a9372e4246373418e694cac33b4353befd95487047d856bc?d=identicon)[ArtisticPhoenix](/maintainers/ArtisticPhoenix)

---

Top Contributors

[![ArtisticPhoenix](https://avatars.githubusercontent.com/u/8208075?v=4)](https://github.com/ArtisticPhoenix "ArtisticPhoenix (50 commits)")[![hdurham](https://avatars.githubusercontent.com/u/53230651?v=4)](https://github.com/hdurham "hdurham (17 commits)")

---

Tags

debug

### Embed Badge

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

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

###  Alternatives

[symfony/var-dumper

Provides mechanisms for walking through any arbitrary PHP variable

7.4k855.5M8.0k](/packages/symfony-var-dumper)[barryvdh/laravel-debugbar

PHP Debugbar integration for Laravel

19.1k124.3M624](/packages/barryvdh-laravel-debugbar)[php-debugbar/php-debugbar

Debug bar in the browser for php application

4.4k21.3M40](/packages/php-debugbar-php-debugbar)[fruitcake/laravel-debugbar

PHP Debugbar integration for Laravel

19.1k662.9k29](/packages/fruitcake-laravel-debugbar)[kint-php/kint

Kint - Advanced PHP dumper

2.8k19.3M283](/packages/kint-php-kint)[tracy/tracy

😎 Tracy: the addictive tool to ease debugging PHP code for cool developers. Friendly design, logging, profiler, advanced features like debugging AJAX calls or CLI support. You will love it.

1.8k24.4M1.3k](/packages/tracy-tracy)

PHPackages © 2026

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