2017 © Pedro Peláez
 

library vardump

Helper library to print variables for debugging purposes

image

kayalion/vardump

Helper library to print variables for debugging purposes

  • Wednesday, November 16, 2016
  • by kayalion
  • Repository
  • 2 Watchers
  • 4 Stars
  • 477 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 12 Versions
  • 8 % Grown

The README.md

VarDump

PHP Helper library to print variables for debugging purposes., (*1)

Usage

<?php

// dumps a variable
vd("any variable");

// or multiple variables, as many as your memory can handle
vd("any variable", "any other variable");

// dumps a variable and dies
vdd("any variable");

// or with multiple variables
vdd("any variable", "any other variable");

// dumps one variable with a specific configuration
// set any configuration parameter to null to use the global value
$maxRecursiveDepth = 10;
$maxStringLength = 100;
$includeMethods = true;
$theme = new SpidermanHtmlVarDumpTheme();

vdc("any variable", $maxRecursiveDepth, $maxStringLength, $includeMethods, $theme);

// dumps one variable with a specific configuration and dies
vdcd("any variable", $maxRecursiveDepth, $maxStringLength, $includeMethods, $theme);

// as called for the sample screenshots
vd([
    null,
    true,
    42,
    3.1415,
    "any string",
    new Exception(),
    fopen('php://stdout', 'w'),
]);

Screenshots

Output on a HTML page:, (*2)

Screenshot HTML, (*3)

Output in a CLI:, (*4)

Screenshot CLI, (*5)

Configuration

You can use the environment variable to configure the vardump., (*6)

<?php

// Flag to see if object methods should be included
$_ENV['VAR_DUMP_METHODS'] = true;

// Maximum depth for arrays and objects
$_ENV['VAR_DUMP_RECURSIVE_DEPTH'] = 10;

// Maximum length for the preview of a string
$_ENV['VAR_DUMP_STRING_LENGTH'] = 100;

// Name of the CLI theme class
$_ENV['VAR_DUMP_THEME_CLI'] = 'CliVarDumpTheme';

// Name of the HTML theme class, choose between:
// - HtmlVarDumpTheme
// - BatmanHtmlVarDumpTheme
// - HulkHtmlVarDumpTheme,
// - IronmanHtmlVarDumpTheme,
// - SpidermanHtmlVarDumpTheme,
// - SupermanHtmlVarDumpTheme,
$_ENV['VAR_DUMP_THEME_HTML'] = 'SpidermanHtmlVarDumpTheme';

Dump To File

When you are debugging a web application, output can break your layout or response, especially when developing a restful API., (*7)

You can easily pipe the vardump output to a file using the file theme., (*8)

<?php

// the file to dump to
$file = __DIR__ . '/vardump.log';

// create a theme to log to the file
$theme = new FileVarDumpTheme($file);

// you can also provide a truncate size in KB, defaults to 1MB
$theme = new FileVarDumpTheme($file, 4096); // 4MB

// set the theme for both environments
$_ENV['VAR_DUMP_THEME_CLI'] = $theme;
$_ENV['VAR_DUMP_THEME_HTML'] = $theme;

Once the log file is created, you can use the tail command to keep an eye on it:, (*9)

tail -f vardump.log

Installation

You can use Composer to install this helper into your project., (*10)

composer require kayalion/vardump

For manual installation, copy the src/VarDump.php file to your project and include it like:, (*11)

<?php 

include __DIR__ . '/src/VarDump.php';

The Versions

16/11 2016

dev-master

9999999-dev

Helper library to print variables for debugging purposes

  Sources   Download

MIT

by Joris Vandeweerd

debug

16/11 2016

dev-develop

dev-develop

Helper library to print variables for debugging purposes

  Sources   Download

MIT

by Joris Vandeweerd

debug

16/11 2016

4.1.1

4.1.1.0

Helper library to print variables for debugging purposes

  Sources   Download

MIT

by Joris Vandeweerd

debug

16/11 2016

4.1.0

4.1.0.0

Helper library to print variables for debugging purposes

  Sources   Download

MIT

by Joris Vandeweerd

debug

15/11 2016

4.0.0

4.0.0.0

Helper library to print variables for debugging purposes

  Sources   Download

MIT

by Joris Vandeweerd

debug

15/11 2016

3.0.1

3.0.1.0

Helper library to print variables for debugging purposes

  Sources   Download

MIT

by Joris Vandeweerd

debug

14/11 2016

3.0.0

3.0.0.0

Helper library to print variables for debugging purposes

  Sources   Download

MIT

by Joris Vandeweerd

debug

14/11 2016

2.1.2

2.1.2.0

Helper library to print variables for debugging purposes

  Sources   Download

MIT

by Joris Vandeweerd

debug

14/11 2016

2.1.1

2.1.1.0

Helper library to print variables for debugging purposes

  Sources   Download

MIT

by Joris Vandeweerd

debug

14/11 2016

2.1.0

2.1.0.0

Helper library to print variables for debugging purposes

  Sources   Download

MIT

by Joris Vandeweerd

debug

14/11 2016

2.0.0

2.0.0.0

Helper library to print variables for debugging purposes

  Sources   Download

MIT

by Joris Vandeweerd

debug

13/11 2016

1.0.0

1.0.0.0

Helper library to print variables for debugging purposes

  Sources   Download

MIT

by Joris Vandeweerd

debug