PHP TypeLang Help

Array Key Coercion

Cast passed value into a PHP "array key" type. An "array key" in PHP it can be one of two types, either a string or an int number.

Input Value

Output Result

Description

string(T)

string(T)

Returns string value "as is"

int(T)

int(T)

Returns int value "as is"

bool(false)

int(0)

bool(true)

int(1)

null

int(0)

float(T)

int(T)

Converts float to an int without losing precision [1]

Stringable

string(T)

Converts Stringable object to a string [2]

BackedEnum

string(BackedEnum::$value)

Returns the value of the backed enum's case

UnitEnum

string(UnitEnum::$name)

Returns the name of the unit enum's case

Other

never

Throws InvalidValueException exception

Notes

  1. The float value must satisfy the following rules:

    • Must not be more than PHP_INT_MAX

    • Must not be less than PHP_INT_MIN

    • The mantissa should be 0 (should be no loss of precision)

  2. For objects implementing the Stringable interface, the __toString() method will be called.

05 November 2025