core
Table of Contents
Namespaces
- accessors
- arrays
- bits
- callables
- cbor
- date
- documents
- env
- helpers
- json
- maths
- numbers
- objects
- options
- reflections
- strings
Functions
- ifNull() : mixed
- Returns the given value if it is not null; otherwise, returns the default value.
- isLiteral() : bool
- Checks whether a given value is a literal string representing a boolean (`true` or `false`) or `null`.
- normalize() : mixed|null
- Normalizes a value according to the given cleaning flags.
- toNumber() : float|int|false
- Converts a value to a numeric type (int or float) if possible.
Functions
ifNull()
Returns the given value if it is not null; otherwise, returns the default value.
ifNull(mixed $value[, mixed $default = null ]) : mixed
This function is useful to provide a fallback value when a variable might be null.
Parameters
- $value : mixed
-
The value to evaluate.
- $default : mixed = null
-
The default value to return if $value is null. Defaults to null.
Tags
Return values
mixed —Returns $value if it is not null; otherwise returns $default.
isLiteral()
Checks whether a given value is a literal string representing a boolean (`true` or `false`) or `null`.
isLiteral(mixed $value) : bool
This function returns true only if the value is a string and equals (case-insensitive)
to one of the three literal values: "true", "false", or "null".
Parameters
- $value : mixed
-
The value to test.
Tags
Return values
bool —Returns true if the value is a string and matches "true", "false", or "null" (case-insensitive).
normalize()
Normalizes a value according to the given cleaning flags.
normalize(mixed $value[, int $flags = CleanFlag::NORMALIZE ]) : mixed|null
- Arrays are cleaned recursively using the provided flags.
- Strings are trimmed if
CleanFlag::TRIMis set, and empty strings become null ifCleanFlag::EMPTYis set. - Other scalar values are returned as-is, unless
CleanFlag::FALSYis used.
Parameters
- $value : mixed
-
The value to normalize (array or scalar).
- $flags : int = CleanFlag::NORMALIZE
-
A bitmask of CleanFlag values. Defaults to
CleanFlag::DEFAULT | CleanFlag::RETURN_NULL.
Tags
Return values
mixed|null —The normalized value, cleaned array, or null if the result is empty and RETURN_NULL is set.
toNumber()
Converts a value to a numeric type (int or float) if possible.
toNumber(mixed $value[, int|float|false $default = false ]) : float|int|false
Returns false if the value cannot be interpreted as a number.
This is useful to safely normalize user input or data that might contain numeric strings.
Parameters
- $value : mixed
-
The value to convert.
- $default : int|float|false = false
-
The default value if the value is not a numeric value.