{"record":{"id":"87d0e50d4352f6fe","repo":"laravel/framework","slug":"array-value-for-key-s-must-be-a-string-s-foun","errorCode":null,"errorMessage":"Array value for key [%s] must be a string, %s found.","messagePattern":"Array value for key \\[(.+?)\\] must be a string, (.+?) found\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Collections/Arr.php","lineNumber":1193,"sourceCode":"     * @param  int-mask-of<SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_LOCALE_STRING|SORT_NATURAL|SORT_FLAG_CASE>  $options\n     * @return array<TKey, TValue>\n     */\n    public static function sortRecursiveDesc($array, $options = SORT_REGULAR)\n    {\n        return static::sortRecursive($array, $options, SortDirection::Descending);\n    }\n\n    /**\n     * Get a string item from an array using \"dot\" notation.\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public static function string(ArrayAccess|array $array, string|int|null $key, ?string $default = null): string\n    {\n        $value = Arr::get($array, $key, $default);\n\n        if (! is_string($value)) {\n            throw new InvalidArgumentException(\n                sprintf('Array value for key [%s] must be a string, %s found.', $key, gettype($value))\n            );\n        }\n\n        return $value;\n    }\n\n    /**\n     * Conditionally compile classes from an array into a CSS class list.\n     *\n     * @param  array<string, bool>|array<int, string|int>|string  $array\n     * @return ($array is array<string, false> ? '' : ($array is '' ? '' : ($array is array{} ? '' : non-empty-string)))\n     */\n    public static function toCssClasses($array)\n    {\n        $classList = static::wrap($array);\n\n        $classes = [];","sourceCodeStart":1175,"sourceCodeEnd":1211,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Collections/Arr.php#L1175-L1211","documentation":"Thrown by Arr::string() when the resolved dot-notation value is not a string. Numeric/int/bool/null/array values all fail; this is a strict assertion with no coercion.","triggerScenarios":"Calling Arr::string($data, 'key') where the value is an int, float, bool, null (miss), or array.","commonSituations":"JSON where a value is numeric rather than string; missing keys without default; IDs stored as integers.","solutions":["Pass a string default: Arr::string($data, 'key', '').","Cast the source: (string) $data['name'] before lookup.","Use Arr::get() and cast manually for mixed-type inputs."],"exampleFix":"// before\n$name = Arr::string($payload, 'name'); // int throws\n// after\n$name = Arr::string($payload, 'name', '');","handlingStrategy":"validation","validationCode":"$raw = Arr::get($data, 'name');\nif (! is_string($raw)) {\n    $raw = is_null($raw) ? '' : (string) $raw;\n}\n// or pass a default.","typeGuard":"function isStrictString(mixed $value): bool { return is_string($value); }","tryCatchPattern":"try {\n    $name = Arr::string($payload, 'name');\n} catch (\\InvalidArgumentException $e) {\n    $name = '';\n}","preventionTips":["Cast scalars to string at input boundaries.","Pass a string default.","Validate API field types before reading."],"tags":["collections","array","type-mismatch","laravel"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}