Documentation

ValueFormatter
in package

Value formatter class

Turns a real PHP value into its PHP literal source form. Shared by PropertyGenerator, ConstantGenerator, and FunctionTrait's argument-default formatting so all three format values the same way instead of each carrying its own (previously divergent) copy of this logic.

Tags
category

Pop

author

Nick Sagona, III nick@popphp.org

copyright

Copyright (c) 2009-2026 Nick Sagona, III

license

https://www.popphp.org/license New BSD License

version
6.0.0

Table of Contents

Methods

format()  : string
Format a value as PHP literal source (no trailing semicolon)
formatArray()  : string
Format an array value as PHP bracket-literal source
formatArrayCompact()  : string
Format a non-empty array value as a single-line PHP bracket-literal source

Methods

format()

Format a value as PHP literal source (no trailing semicolon)

public static format(mixed $value[, string|null $type = null ][, string $indent = '' ][, bool $compact = false ]) : string
Parameters
$value : mixed
$type : string|null = null
$indent : string = ''
$compact : bool = false

render an array value on a single line instead of the default multi-line bracket-literal form -- used for attribute arguments, which always render inline (even a top-level #[...] is conventionally one physical line) and would otherwise force a multi-line array literal into the middle of a parameter list

Return values
string

formatArray()

Format an array value as PHP bracket-literal source

protected static formatArray(array<string|int, mixed> $value, string $indent) : string
Parameters
$value : array<string|int, mixed>
$indent : string
Return values
string

formatArrayCompact()

Format a non-empty array value as a single-line PHP bracket-literal source

protected static formatArrayCompact(array<string|int, mixed> $value) : string
Parameters
$value : array<string|int, mixed>
Return values
string

        
On this page

Search results