{"record":{"id":"3c79f96e7ca87c22","repo":"phalcon/cphalcon","slug":"the-parameter-must-be-array-or-string","errorCode":null,"errorMessage":"The parameter must be 'array' or 'string'","messagePattern":"The parameter must be 'array' or 'string'","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"phalcon/Auth/Guard/UserRemember.zep","lineNumber":43,"sourceCode":"{\n    /**\n     * @var int|string|null\n     */\n    protected id;\n    protected string token;\n    protected string userAgent;\n\n    /**\n     * Accepts either the raw JSON cookie value (string) or the already\n     * decoded associative array. Malformed input degrades to an empty\n     * payload so callers can read getters without null-guarding.\n     *\n     * @param array<string, mixed>|string $payload\n     */\n    public function __construct(var payload)\n    {\n        if (typeof payload !== \"array\" && typeof payload !== \"string\") {\n            throw new \\TypeError(\"The parameter must be 'array' or 'string'\");\n        }\n\n        var data, rawId;\n\n        try {\n            let data = typeof payload === \"string\" ? (new Decode())->__invoke(payload, true) : payload;\n        } catch InvalidArgumentException {\n            let data = [];\n        }\n\n        if (typeof data !== \"array\") {\n            let data = [];\n        }\n\n        /** @var RememberPayload $data */\n        let rawId = isset(data[\"id\"]) ? data[\"id\"] : null;\n\n        let this->id        = (typeof rawId === \"int\" || typeof rawId === \"string\") ? rawId : null;","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Auth/Guard/UserRemember.zep#L25-L61","documentation":"Phalcon\\Auth\\Guard\\UserRemember is a value object wrapping a remember-me cookie payload. Its constructor accepts only a string (raw JSON from the cookie) or an array (already-decoded payload); anything else throws \\TypeError before parsing (phalcon/Auth/Guard/UserRemember.zep:43). Note the guard is type-only: malformed JSON strings deliberately degrade to an empty payload (InvalidArgumentException is caught), so this error means the caller passed the wrong type, not bad JSON.","triggerScenarios":"new UserRemember(null) — e.g. ($_COOKIE['remember'] ?? null) when the cookie is absent; passing an int/bool/stdClass; json_decode($raw) without the true flag producing stdClass.","commonSituations":"Reading a possibly-missing cookie without a default; a refactor changes the producer to write arrays while an older path still passes null; test code passing 0 or false as a sentinel; decoded values forwarded without re-flagging as arrays.","solutions":["Default the input: new UserRemember($_COOKIE['remember'] ?? '') — an empty string yields an empty, safely-readable payload.","If decoding yourself, use json_decode($raw, true) so you pass an array, not stdClass.","Guard the boundary with is_string()/is_array() when the value comes from untrusted or legacy storage."],"exampleFix":"// before\n$remember = new UserRemember($_COOKIE['remember-me'] ?? null); // TypeError\n\n// after\n$remember = new UserRemember($_COOKIE['remember-me'] ?? '');","handlingStrategy":"type-guard","validationCode":"$raw = $_COOKIE['remember-me'] ?? '';\nif (!is_string($raw)) {\n    $raw = ''; // cookie storage is always string; belt-and-braces for tests\n}","typeGuard":"/** @param mixed $value @return array|string */\nfunction normalizeRememberPayload(mixed $value): array|string\n{\n    return (is_string($value) || is_array($value)) ? $value : '';\n}\n\n$remember = new UserRemember(normalizeRememberPayload($payload));","tryCatchPattern":null,"preventionTips":["Always coalesce cookie reads with '' — never null.","Decode JSON with the true flag (associative) before passing arrays around.","Rely on the constructor's graceful degradation: empty payloads are safe to read via the getters."],"tags":["phalcon","auth","remember-me","typeerror","cookie"],"backgroundTag":"invalid-argument-type","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}