A library for generating string representations of any value, inspired by Python's reprlib library.
Repr provides a way to generate informational string representations of any value, inspired by Python's reprlib library.
composer require icecave/repr
Repr::repr() method to obtain a string representation for any type.
use Icecave\Repr\Repr; echo Repr::repr([1, 2, 3]);
The output from the example above is:
[1, 2, 3]
Arrays are represented using PHP 5.4 style short array notation. By default a maximum of 3 elements are shown along with a count of any additional elements. Nested arrays are represented up to 3 levels deep by default, with any arrays nested deeper than this showing only the element count.
Numbers are represented naturally, floating point values will always display a decimal point even if representing a whole number.
Strings are represented enclosed in double quotes up to a default maximum length of 50 characters. Any control characters are shown as escape sequences.
Objects are represented as a class name and SPL object hash enclosed in angle brackets. If the object has a
method, the result of this is shown after the class name according to the rules of string representations specified
If an object implements RepresentableInterface, the result of its stringRepresentation() method is used instead.
Resources are represented as a resource type and ID enclosed in angle brackets. Stream resources will also display the stream mode.
All other types are represented by the result of var_export() in lowercase.