PHP TypeLang Help

Integer Coercion

Cast passed value into a PHP int type.

Input Value

Output Result

Description

int(T)

int(T)

Returns int value "as is"

BackedEnum<int>

int(BackedEnum<int>::$value)

Returns the value of the int backed enum case

string(T)

int(T)

Converts string to an integer value [1]

float(T)

int(T)

Converts float to an integer value [2]

bool(false)

int(0)

bool(true)

int(1)

null

int(0)

Other

never

Throws InvalidValueException exception

Notes

  1. The string value must satisfy the following rules:

    • Must be non-empty

    • Must contain integer-like numeric value or must float-like allowing casting without loss of accuracy [2]

  2. 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)

05 November 2025