{"record":{"id":"868f2bedcb5c37d9","repo":"gchq/CyberChef","slug":"encountered-a-non-implemented-type-typeof-conte","errorCode":null,"errorMessage":"Encountered a non-implemented type: ${typeof content}","messagePattern":"Encountered a non-implemented type: (.+?)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/PHPSerialize.mjs","lineNumber":77,"sourceCode":"             * cast to 0 or 1\n             */\n            if (typeof content === \"boolean\") {\n                return `${basicTypes.boolean}:${content ? 1 : 0}`;\n            }\n            /* Numbers */\n            if (typeof content === \"number\") {\n                if (isInteger(content)) {\n                    return `${basicTypes.integer}:${content.toString()}`;\n                } else {\n                    return `${basicTypes.float}:${content.toString()}`;\n                }\n            }\n            /* Strings */\n            if (typeof content === \"string\")\n                return `${basicTypes.string}:${content.length}:\"${content}\"`;\n\n            /** This should be unreachable */\n            throw new OperationError(`Encountered a non-implemented type: ${typeof content}`);\n        }\n\n        /**\n         * Recursively serialize\n         * @param {*} object\n         * @returns {string}\n         */\n        function serialize(object) {\n            /* Null */\n            if (object == null) {\n                return `N;`;\n            }\n\n            if (typeof object !== \"object\") {\n                /* Basic types */\n                return `${serializeBasicTypes(object)};`;\n            } else if (object instanceof Array) {\n                /* Arrays */","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/PHPSerialize.mjs#L59-L95","documentation":"The serializeBasicTypes() function handles boolean, number, and string. If none match (the value is a BigInt, Symbol, undefined, or function disguised as a primitive), this 'should be unreachable' throw fires. It is a defensive guard for types the serializer was never designed to handle at the leaf level.","triggerScenarios":"A JSON value that is a Symbol or BigInt reaches serializeBasicTypes because typeof returns 'symbol' or 'bigint', neither of which matches the boolean/number/string branches. A function value whose typeof is 'function' could also reach here if it bypasses the object check upstream.","commonSituations":"Input JSON contains a BigInt (typeof 'bigint') or Symbol (typeof 'symbol'). A JSON revival function injected non-standard primitive types. The operation is called programmatically with a parsed JSON object containing non-JSON-safe values.","solutions":["Ensure all leaf values in the JSON input are plain booleans, numbers, or strings","Convert BigInt values to regular numbers or strings before passing them in","Remove or stringify any Symbol-keyed or Symbol-valued properties"],"exampleFix":"// before\nconst data = { id: BigInt(123), name: \"test\" };\n// after\nconst data = { id: Number(123), name: \"test\" };","handlingStrategy":"type-guard","validationCode":"// Pre-check: ensure no unsupported primitive types\nfunction hasUnsupportedPrimitives(obj) {\n  for (const v of Object.values(obj)) {\n    if (typeof v === 'bigint' || typeof v === 'symbol') return true;\n    if (typeof v === 'object' && v !== null) {\n      if (hasUnsupportedPrimitives(v)) return true;\n    }\n  }\n  return false;\n}","typeGuard":"function isSerializablePrimitive(v) {\n  return typeof v === 'boolean' || typeof v === 'number' || typeof v === 'string';\n}","tryCatchPattern":"try {\n  const result = chef.phpSerialize(input);\n} catch (e) {\n  if (/non-implemented type/i.test(e.message)) {\n    console.error(\"Unsupported primitive type — convert BigInts/Symbols to strings or numbers\");\n  } else { throw e; }\n}","preventionTips":["Convert BigInt values to Number or String before serializing","Remove Symbol-typed properties from the input","Run JSON.parse(JSON.stringify(data)) to strip non-JSON-safe types"],"tags":["php","serialization","type-error","unreachable-guard"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}