toPhpHumanReadableScalar.php
Table of Contents
Functions
- toPhpHumanReadableScalar() : string
- Converts a scalar value (string, boolean, float, etc.) to a simplified, human-readable PHP string representation.
Functions
toPhpHumanReadableScalar()
Converts a scalar value (string, boolean, float, etc.) to a simplified, human-readable PHP string representation.
toPhpHumanReadableScalar(mixed $value[, string $quote = 'single' ][, bool $compact = false ]) : string
Useful when a less verbose and more natural output is desired, especially for inline dumps or generated code. Supports custom quote style for strings ('single' or 'double') and optional compact escaping (control characters and trimming).
- Strings are quoted and escaped appropriately using formatQuotedString().
- Booleans are represented as
true
orfalse
. - Floats with no decimal part (e.g., 42.0) are simplified as integers (e.g.,
42
). - Null is represented as
null
. - Other types (e.g. arrays, objects) fall back to
var_export()
representation.
Parameters
- $value : mixed
-
The scalar value to convert.
- $quote : string = 'single'
-
The quote style for strings:
'single'
or'double'
. Default is'single'
. - $compact : bool = false
-
If true, trims and escapes control characters in strings, even with single quotes.
Tags
Return values
string —The human-readable PHP representation of the scalar value.