A library for generating string representations of any value, inspired by Python's reprlib library.

Installs: 37 428

Dependents: 6

Stars: 7

Watchers: 2

Forks: 1

Open Issues: 1

1.0.1 2014-07-25 05:44 UTC


Build Status Test Coverage SemVer

Repr provides a way to generate informational string representations of any value, inspired by Python's reprlib library.


Use the Repr::repr() method to obtain a string representation for any type.

use Icecave\Repr\Repr;

echo Repr::repr(array(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.

Numeric Values

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 __toString method, the result of this is shown after the class name according to the rules of string representations specified above.

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.

Other Types

All other types are represented by the result of var_export() in lowercase.

Contact us