Page MenuHomePhabricator
Diviner Arcanist Tech Docs PhutilReadableSerializer

final class PhutilReadableSerializer
Arcanist 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`.

Methods

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