laravel/framework · error · InvalidArgumentException
Array value for key [%s] must be a boolean, %s found.
Error message
Array value for key [%s] must be a boolean, %s found.
What it means
Thrown by Arr::boolean() when the value resolved via Arr::get() fails is_bool(). The accessor does not coerce 0/1/'true', so those values and null all trigger it.
Source
Thrown at src/Illuminate/Collections/Arr.php:105
throw new InvalidArgumentException(
sprintf('Array value for key [%s] must be an array, %s found.', $key, gettype($value))
);
}
return $value;
}
/**
* Get a boolean item from an array using "dot" notation.
*
* @throws \InvalidArgumentException
*/
public static function boolean(ArrayAccess|array $array, string|int|null $key, ?bool $default = null): bool
{
$value = Arr::get($array, $key, $default);
if (! is_bool($value)) {
throw new InvalidArgumentException(
sprintf('Array value for key [%s] must be a boolean, %s found.', $key, gettype($value))
);
}
return $value;
}
/**
* Collapse an array of arrays into a single array.
*
* @param iterable $array
* @return array
*/
public static function collapse($array)
{
$results = [];
foreach ($array as $values) {View on GitHub (pinned to bd6b5437e6)
Solutions
- Pass a bool default: Arr::boolean($data, 'enabled', false).
- Normalize the source: cast with filter_var($v, FILTER_VALIDATE_BOOLEAN) before storing/reading.
- Validate first: $v = Arr::get($data, 'enabled'); if (is_bool($v)) { ... }.
- Fix the dot path or schema so the key genuinely contains a bool.
Example fix
// before $on = Arr::boolean($payload, 'features.beta'); // after $on = Arr::boolean($payload, 'features.beta', false); // or normalize $raw = Arr::get($payload, 'features.beta'); $on = is_bool($raw) ? $raw : filter_var($raw, FILTER_VALIDATE_BOOLEAN);
Defensive patterns
Strategy: type-guard
Validate before calling
$value = Arr::get($data, 'enabled');
if (! is_bool($value)) {
$value = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ?? false;
} Type guard
function arrayKeyIsBool(array $array, string $key): bool {
return is_bool(Arr::get($array, $key));
} Try / catch
try {
$on = Arr::boolean($data, 'enabled', false);
} catch (\InvalidArgumentException $e) {
$on = false;
} Prevention
- Normalize truthy/falsy values with filter_var(FILTER_VALIDATE_BOOLEAN) before reading.
- Pass a bool default to Arr::boolean().
- Avoid storing flags as 0/1 ints where they will be read as bools.
When it happens
Trigger: Calling Arr::boolean($data, 'enabled') when the value is 1, 0, 'true', 'false', an array, or null (missing key, no bool default).
Common situations: Decoding JSON whose booleans came through as 'true'/'false' strings; reading a database/config value stored as tinyint(1) yielding 0/1; missing key with no default.
Related errors
- Array value for key [%s] must be an array, %s found.
- Array value for key [%s] must be a float, %s found.
- Items cannot be represented by a scalar value.
- Array value for key [%s] must be an integer, %s found.
- Array value for key [%s] must be a string, %s found.
AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06).
Data as JSON: /data/errors/b97f7e492e2ed88c.json.
Report an issue: GitHub.