Coerce
API reference › Debug Core › Helper › Coerce
Narrows arbitrary mixed payloads into the typed scalars debug-panel renderers expect.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
float() static | Returns a numeric value as a float or the supplied default. | Coerce |
floatOrNull() static | Returns the value as a float when it is numeric, null otherwise. | Coerce |
int() static | Returns a numeric value as an int or the supplied default. | Coerce |
intOrNull() static | Returns the value as an int when it is numeric, null otherwise. | Coerce |
string() static | Returns a string value or the supplied default. | Coerce |
stringKeyedArray() static | Returns only the entries of $data whose key is a string, preserving order. | Coerce |
stringList() static | Returns only the string entries of a raw list, preserving order. | Coerce |
stringOrNull() static | Returns the value as a string when it is scalar or Stringable, null otherwise. | Coerce |
traceFrames() static | Narrows a raw trace value (as captured by Yii’s logger) into the list<array<string, shape every panel renderer consumes. | Coerce |
Method details
Section titled “Method details”float()
Section titled “float() ”public static function float(mixed $value, float $default = 0.0): floatReturns a numeric value as a float or the supplied default.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | mixed | Value to narrow. |
$default | float | Value returned for non-numeric input. |
Returns
float: Numeric value or the configured default.
floatOrNull()
Section titled “floatOrNull() ”public static function floatOrNull(mixed $value): float|nullReturns the value as a float when it is numeric, null otherwise.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | mixed | Value to narrow. |
Returns
float|null: Numeric value or null.
int()
Section titled “int() ”public static function int(mixed $value, int $default = 0): intReturns a numeric value as an int or the supplied default.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | mixed | Value to narrow. |
$default | int | Value returned for non-numeric input. |
Returns
int: Numeric value or the configured default.
intOrNull()
Section titled “intOrNull() ”public static function intOrNull(mixed $value): int|nullReturns the value as an int when it is numeric, null otherwise.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | mixed | Value to narrow. |
Returns
int|null: Numeric value or null.
string()
Section titled “string() ”public static function string(mixed $value, string $default = ''): stringReturns a string value or the supplied default.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | mixed | Value to narrow. |
$default | string | Value returned for non-string input. |
Returns
string: String value or the configured default.
stringKeyedArray()
Section titled “stringKeyedArray() ”public static function stringKeyedArray(array<array-key, mixed> $data): array<string, mixed>Returns only the entries of $data whose key is a string, preserving order.
Narrows a mixed/array<array-key, mixed> snapshot down to the array<string, mixed> shape downstream view-model
normalizers expect.
Parameters
| Parameter | Type | Description |
|---|---|---|
$data | array<array-key, | Source array with arbitrary keys. |
Returns
array<string, mixed>: Entries whose key was already a string, in original order.
stringList()
Section titled “stringList() ”public static function stringList(mixed $values): list<string>Returns only the string entries of a raw list, preserving order.
Parameters
| Parameter | Type | Description |
|---|---|---|
$values | mixed | Raw list, typically a user-configured category list. |
Returns
list<string>: String entries in original order, possibly empty.
stringOrNull()
Section titled “stringOrNull() ”public static function stringOrNull(mixed $value): string|nullReturns the value as a string when it is scalar or Stringable, null otherwise.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | mixed | Value to narrow. |
Returns
string|null: String representation or null.
traceFrames()
Section titled “traceFrames() ”public static function traceFrames(mixed $value): list<array<string, mixed>>Narrows a raw trace value (as captured by Yii’s logger) into the list<array<string, mixed>> shape every panel
renderer consumes.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | mixed | Raw trace payload. |
Returns
list<array<string, mixed>>: Trace frames normalized to string-keyed maps.