Documentation

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 null value
  • 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
throws
TypeError

if the type is not supported by the specific case

throws
ValueError

if circular reference is detected

Return values
string|null

isCoercible()

public isCoercible(mixed $value) : bool
Parameters
$value : mixed
Return values
bool

        
On this page

Search results