Page MenuHomePhorge
Diviner libphutil Tech Docs PhutilReadableSerializer

final class PhutilReadableSerializer
libphutil Technical Documentation ()

Serialize PHP values and objects into a human-readable format, useful for displaying errors.

Tasks

Printing PHP Values

  • public static function printableValue($value) — Given a value, makes the best attempt at returning a string representation of that value suitable for printing. This method returns a //complete// representation of the value; use @{method:printShort} or @{method:printShallow} to summarize values.
  • public static function printShort($value) — Print a concise, human readable representation of a value.
  • public static function printShallow($value, $max_depth, $max_members) — Dump some debug output about an object's members without the potential recursive explosion of verbosity that comes with `print_r()`.

Internals

  • private static function printShallowRecursive($value, $max_depth, $max_members, $depth, $indent) — Implementation for @{method:printShallow}.
  • private static function addIndentation($value, $indent, $first_line) — Adds indentation to the beginning of every line starting from `$first_line`.

Other Methods

Methods

public function __get($name)
Inherited

This method is not documented.
Parameters
$name
Return
wild

public function __set($name, $value)
Inherited

This method is not documented.
Parameters
$name
$value
Return
wild

public function current()
Inherited

This method is not documented.
Return
wild

public function key()
Inherited

This method is not documented.
Return
wild

public function next()
Inherited

This method is not documented.
Return
wild

public function rewind()
Inherited

This method is not documented.
Return
wild

public function valid()
Inherited

This method is not documented.
Return
wild

private function throwOnAttemptedIteration()
Inherited

This method is not documented.
Return
wild

public function getPhobjectClassConstant($key, $byte_limit)
Inherited

Phobject

Read the value of a class constant.

This is the same as just typing self::CONSTANTNAME, but throws a more useful message if the constant is not defined and allows the constant to be limited to a maximum length.

Parameters
string$keyName of the constant.
int|null$byte_limitMaximum number of bytes permitted in the value.
Return
stringValue of the constant.

public static function printableValue($value)

Given a value, makes the best attempt at returning a string representation of that value suitable for printing. This method returns a complete representation of the value; use printShort() or printShallow() to summarize values.

Parameters
wild$valueAny value.
Return
stringHuman-readable representation of the value.

public static function printShort($value)

Print a concise, human readable representation of a value.

Parameters
wild$valueAny value.
Return
stringHuman-readable short representation of the value.

public static function printShallow($value, $max_depth, $max_members)

Dump some debug output about an object's members without the potential recursive explosion of verbosity that comes with print_r().

To print any number of member variables, pass null for $max_members.

Parameters
wild$valueAny value.
int$max_depthMaximum depth to print for nested arrays and objects.
int$max_membersMaximum number of values to print at each level.
Return
stringHuman-readable shallow representation of the value.

private static function printShallowRecursive($value, $max_depth, $max_members, $depth, $indent)

Implementation for printShallow().

Parameters
wild$valueAny value.
int$max_depthMaximum depth to print for nested arrays and objects.
int$max_membersMaximum number of values to print at each level.
int$depthCurrent depth.
string$indentIndentation string.
Return
stringHuman-readable shallow representation of the value.

private static function addIndentation($value, $indent, $first_line)

Adds indentation to the beginning of every line starting from $first_line.

Parameters
string$valuePrinted value.
string$indentString to indent with.
int$first_lineIndex of first line to indent.
Return
string