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

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

concept-labs/debug
==================

(C)oncept-Labs Arrays API

1.1.0(7mo ago)05MITPHPPHP &gt;=8.0

Since Aug 20Pushed 7mo agoCompare

[ Source](https://github.com/Concept-Labs/debug)[ Packagist](https://packagist.org/packages/concept-labs/debug)[ RSS](/packages/concept-labs-debug/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)DependenciesVersions (5)Used By (0)

Debug Package
=============

[](#debug-package)

[![PHP Version](https://camo.githubusercontent.com/c5e8da782b1a0673c08b4f474108036d2cc973470eed2d5d89d48e8c8475eee6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e322d626c75652e737667)](https://www.php.net/)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![Concept](https://camo.githubusercontent.com/96fca7f97b28cca35c3283566ebb4261cebf1177103b1ced090be68444c1e775/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f6e636570742d45636f73797374656d2d76696f6c65742e737667)](https://github.com/Concept-Labs)

A powerful PHP debugging and profiling library providing comprehensive tools for debugging, performance analysis, memory profiling, and more.

Installation
------------

[](#installation)

```
composer require concept-labs/debug
```

Features
--------

[](#features)

- 🐛 **Variable Dumping** - Pretty print variables with dump() and dd()
- ⏱️ **Performance Profiling** - Measure execution time and memory usage
- 📊 **Memory Tracking** - Monitor memory consumption and detect leaks
- 📝 **Logging** - Built-in logging with severity levels
- 🔍 **Variable Inspection** - Deep inspection of variable types and properties
- 📚 **Stack Traces** - Formatted backtraces and call stacks
- ✅ **Assertions** - Debug assertions with detailed error messages
- 📈 **Benchmarking** - Measure callback execution time

Usage
-----

[](#usage)

### Basic Debugging

[](#basic-debugging)

```
use Concept\Debug\Debug;

// Dump variables
Debug::dump($var1, $var2, $var3);

// Dump and die
Debug::dd($someVariable);

// Throw exception with context
Debug::throw('Something went wrong', $context);
```

### Performance Profiling

[](#performance-profiling)

```
// Timer API
Debug::timerStart('operation');
// ... your code ...
$elapsed = Debug::timerStop('operation', true); // true = output result

// Get elapsed time without stopping
$currentTime = Debug::timerGet('operation');

// Benchmark a callback
$result = Debug::benchmark(function() {
    // ... code to benchmark ...
    return someValue();
}, 'My Benchmark');

// Profile with detailed metrics
Debug::profileStart('complex-operation');
// ... your code ...
$profile = Debug::profileEnd('complex-operation', true);
// Returns: ['elapsed_time' => ..., 'memory_used' => ...]

// Profile a callback
$data = Debug::profile(function() {
    return expensiveOperation();
}, 'expensive-op');
// Returns: ['result' => ..., 'profile' => [...]]
```

### Memory Profiling

[](#memory-profiling)

```
// Get current memory usage
$bytes = Debug::memoryUsage();
$formatted = Debug::memoryUsage(false, true); // "2.5 MB"

// Get peak memory usage
$peak = Debug::memoryPeak(false, true);

// Take memory snapshots
Debug::memorySnapshot('before-operation');
// ... your code ...
Debug::memorySnapshot('after-operation');

// Compare snapshots
$diff = Debug::memoryDiff('before-operation', 'after-operation', true);
echo "Memory used: $diff";

// Format bytes
echo Debug::formatBytes(1536); // "1.5 KB"
```

### Variable Inspection

[](#variable-inspection)

```
// Get detailed variable information
$info = Debug::inspect($variable);
// Returns: ['type' => 'object', 'class' => 'MyClass', 'methods' => [...], ...]

// Print inspection
Debug::printInspect($variable);

// Calculate variable size
$size = Debug::sizeOf($largeArray);
echo "Variable size: " . Debug::formatBytes($size);

// JSON dump
Debug::json($data);
```

### Stack Traces

[](#stack-traces)

```
// Get backtrace
$trace = Debug::backtrace();

// Print formatted backtrace
Debug::printBacktrace(10); // limit to 10 frames

// Get stack trace as string
$traceString = Debug::getStackTrace();
```

### Logging

[](#logging)

```
// Log messages with severity levels
Debug::log('User logged in', 'info', ['user_id' => 123]);
Debug::log('Database connection failed', 'error');
Debug::log('Deprecated function called', 'warning');

// Get logs
$allLogs = Debug::getLogs();
$errorLogs = Debug::getLogs('error');

// Print logs
Debug::printLogs(); // all logs
Debug::printLogs('error'); // only errors

// Clear logs
Debug::clearLogs();
```

### Assertions

[](#assertions)

```
// Assert conditions
Debug::assert($userId > 0, 'User ID must be positive');

// Non-throwing assertion (logs only)
$isValid = Debug::assert($condition, 'Check failed', false);
```

### Context Information

[](#context-information)

```
// Get execution context
$context = Debug::context();
// Returns: memory usage, peak memory, execution time, included files, PHP version, etc.

// Print context
Debug::printContext();
```

### Utilities

[](#utilities)

```
// Print all active timers
Debug::printTimers();
```

API Reference
-------------

[](#api-reference)

### Basic Debugging Methods

[](#basic-debugging-methods)

- `dump(...$vars)` - Print variables in readable format
- `dd(...$vars)` - Dump and die
- `throw(string $message, ...$vars)` - Throw exception with context

### Performance Methods

[](#performance-methods)

- `timerStart(string $label)` - Start a timer
- `timerStop(string $label, bool $output = false)` - Stop timer and get elapsed time
- `timerGet(string $label)` - Get elapsed time without stopping
- `benchmark(callable $callback, ?string $label = null, bool $output = true)` - Benchmark a callback
- `profileStart(string $label)` - Start profiling
- `profileEnd(string $label, bool $output = false)` - Stop profiling and get results
- `profile(callable $callback, ?string $label = null)` - Profile a callback execution

### Memory Methods

[](#memory-methods)

- `memoryUsage(bool $realUsage = false, bool $formatted = false)` - Get current memory usage
- `memoryPeak(bool $realUsage = false, bool $formatted = false)` - Get peak memory usage
- `memorySnapshot(string $label, bool $realUsage = false)` - Take memory snapshot
- `memoryDiff(string $labelStart, string $labelEnd, bool $formatted = false)` - Compare snapshots
- `formatBytes(int $bytes, int $precision = 2)` - Format bytes to human-readable string

### Inspection Methods

[](#inspection-methods)

- `inspect($var)` - Get detailed variable information
- `printInspect($var)` - Print variable inspection
- `sizeOf($var)` - Calculate variable size in bytes
- `json($var, int $options = ...)` - Dump variable as JSON

### Stack Trace Methods

[](#stack-trace-methods)

- `backtrace(int $limit = 0, int $options = ...)` - Get backtrace array
- `printBacktrace(int $limit = 0)` - Print formatted backtrace
- `getStackTrace(int $limit = 0)` - Get stack trace as string

### Logging Methods

[](#logging-methods)

- `log(string $message, string $level = 'info', array $context = [])` - Log a message
- `getLogs(?string $level = null)` - Get log entries
- `printLogs(?string $level = null)` - Print logs
- `clearLogs()` - Clear all logs

### Assertion Methods

[](#assertion-methods)

- `assert(bool $condition, string $message = 'Assertion failed', bool $throwException = true)` - Assert condition

### Context Methods

[](#context-methods)

- `context()` - Get execution context information
- `printContext()` - Print execution context
- `printTimers()` - Print all active timers

Examples
--------

[](#examples)

### Profile Database Query

[](#profile-database-query)

```
Debug::profileStart('db-query');
$results = $db->query('SELECT * FROM users WHERE active = 1');
$profile = Debug::profileEnd('db-query', true);
// Output: Profile 'db-query':
//   Time: 0.045123 seconds
//   Memory: 2.5 MB
```

### Track Memory Leaks

[](#track-memory-leaks)

```
Debug::memorySnapshot('start');
for ($i = 0; $i < 1000; $i++) {
    processItem($i);
    if ($i % 100 === 0) {
        Debug::memorySnapshot("iteration-$i");
        $diff = Debug::memoryDiff('start', "iteration-$i", true);
        Debug::log("Memory at iteration $i: $diff", 'info');
    }
}
Debug::printLogs();
```

### Benchmark Different Approaches

[](#benchmark-different-approaches)

```
$time1 = Debug::benchmark(function() {
    return array_filter($array, fn($x) => $x > 10);
}, 'Array Filter');

$time2 = Debug::benchmark(function() {
    $result = [];
    foreach ($array as $x) {
        if ($x > 10) $result[] = $x;
    }
    return $result;
}, 'Foreach Loop');

echo "Filter is " . ($time2 / $time1) . "x faster\n";
```

Requirements
------------

[](#requirements)

- PHP &gt;= 8.0

License
-------

[](#license)

MIT License - see LICENSE file for details

Author
------

[](#author)

Viktor Halytskyi -

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance64

Regular maintenance activity

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 55.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 ~27 days

Total

3

Last Release

217d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/39bcfd110a5cc1f2d7ff687193670d00133cf415ad2b9959afaff24ff1e564fd?d=identicon)[vgalitsky](/maintainers/vgalitsky)

---

Top Contributors

[![vgalitsky](https://avatars.githubusercontent.com/u/1241206?v=4)](https://github.com/vgalitsky "vgalitsky (5 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (4 commits)")

---

Tags

phpdebug

### Embed Badge

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

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

###  Alternatives

[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)[h4cc/phpqatools

A meta composer package for PHP QA Tools.

6418.6k1](/packages/h4cc-phpqatools)

PHPackages © 2026

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