2017 © Pedro Peláez
 

library serialize-debugger

A tool for debugging failing or dangerous PHP serialize() calls

image

edemeijer/serialize-debugger

A tool for debugging failing or dangerous PHP serialize() calls

  • Wednesday, October 4, 2017
  • by EdeMeijer
  • Repository
  • 2 Watchers
  • 7 Stars
  • 127 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 22 % Grown

The README.md

serialize-debugger

A tool for debugging failing or dangerous PHP serialize() calls., (*1)

Motivation

Debugging issues with PHP's serialize() method can be a tedious task, because it doesn't give much information when it encounters errors. This is best demonstrated with an example:, (*2)

<?php

$nestedStruct = [
    'foo' => (object) [
        'validProp' => 42,
        'invalidProp' => function () {},
    ],
    'bar' => [
        'someProp' => 'Hello',
    ],
];

$serialized = serialize($nestedStruct);

The above code will result in a fatal error:, (*3)

PHP Fatal error:  Uncaught exception 'Exception' with message 'Serialization of 'Closure' is not allowed' in /path/to/script.php:13
Stack trace:
#0 /path/to/script.php(13): serialize(Array)
#1 {main}
  thrown in /path/to/script.php on line 13

Not very helpful, is it? Where is this closure located exactly? Imagine this happening with big, nested structures, and you're in for a lot of in-the-dark debugging fun., (*4)

This is where serialize-debugger can lend a helping hand. Look at the following PHP snippet and its output:, (*5)

Debugger::debugPlaintext($nestedStruct);
Closure - ERROR
    {root}[foo]->invalidProp

Much better, now we know exactly where the offending closure is located in the problematic data structure., (*6)

Requirements

serialize-debugger is only supported on PHP 5.4.0 and up., (*7)

Installation

Using composer, add to your composer.json:, (*8)

"edemeijer/serialize-debugger": ">=0.1.1"

Then run composer.phar update, (*9)

API

Basic usage:, (*10)

// There are two static convenience methods in the main debugger class:
// Outputting errors and warnings in plain text format
Debugger::debugPlaintext($data);

// Outputting errors and warnings in HTML format
Debugger::debugHTML($data);

// Both methods provide an optional second boolean parameter for verbose output
// This will output not only errors and warnings, but the paths to every element
// in the data set
Debugger::debugPlainText($data, true);

Without using the static convenience methods:, (*11)

$debugger = new Debugger();
$formatter = new PlainTextFormatter();
$result = $debugger->debug($data, $verbose);
echo $formatter->format($result);

License

MIT - See LICENSE file., (*12)

The Versions

04/10 2017

dev-master

9999999-dev

A tool for debugging failing or dangerous PHP serialize() calls

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-reflection *

 

The Development Requires

by Ede Meijer

serialize debugging

07/09 2014

v0.1.4

0.1.4.0

A tool for debugging failing or dangerous PHP serialize() calls

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-reflection *

 

The Development Requires

by Ede Meijer

serialize debugging

02/09 2014

0.1.3

0.1.3.0

A tool for debugging failing or dangerous PHP serialize() calls

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-reflection *

 

The Development Requires

by Ede Meijer

serialize debugging

02/09 2014

0.1.2

0.1.2.0

A tool for debugging failing or dangerous PHP serialize() calls

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-reflection *

 

The Development Requires

by Ede Meijer

serialize debugging

01/09 2014

0.1.1

0.1.1.0

A tool for debugging failing or dangerous PHP serialize() calls

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-reflection *

 

The Development Requires

by Ede Meijer

serialize debugging

28/08 2014

0.1.0

0.1.0.0

A tool for debugging failing or dangerous PHP serialize() calls

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-reflection *

 

The Development Requires

by Ede Meijer

serialize debugging