StringCoercionMode
in package
Table of Contents
Cases
- Ecmascript
- Ecmascript conversion mode.
- Native
- PHP conversion mode.
Methods
- coerce() : string|null
- isCoercible() : bool
- hasCircularReference() : bool
- Array recursion detection.
Cases
Native
PHP conversion mode.
Guarantees that only scalar values, BackedEnum, and null are accepted. Any object, UnitEnum, resource, or recursive structure results in an error.
- null: is not converted and stays the
nullvalue - string: used as-is
- bool: converted to string “0” (false) or “1” (true)
- int: converted to numeric string (123 -> “123”)
- float: converted to decimal string (3.14 -> “3.14”)
- Backed Enum: converted to their backing value and then stringify see int and string
Ecmascript
Ecmascript conversion mode.
Guarantees that only scalar values, BackedEnum, and null are accepted. Any resource, or recursive structure results in an error.
- null: converted to string “null”
- string: used as-is
- bool: converted to string “false” (false) or “true” (true)
- int: converted to numeric string (123 -> “123”)
- float: converted to decimal string (3.14 -> “3.14”), "NaN", "-Infinity" or "Infinity"
- Backed Enum: converted to their backing value and then stringify see int and string
- Array as list are flatten into a string list using the "," character as separator
- Associative array, Unit Enum, any object without stringification semantics is coerced to "[object Object]".
Methods
coerce()
public
coerce(mixed $value) : string|null
Parameters
- $value : mixed
Tags
Return values
string|nullisCoercible()
public
isCoercible(mixed $value) : bool
Parameters
- $value : mixed
Return values
boolhasCircularReference()
Array recursion detection.
private
static hasCircularReference(array<string|int, mixed> &$arr) : bool
Parameters
- $arr : array<string|int, mixed>