{"record":{"id":"fa893a41d4625eaa","repo":"gchq/CyberChef","slug":"encountered-a-non-implemented-type-typeof-objec","errorCode":null,"errorMessage":"Encountered a non-implemented type: ${typeof object}","messagePattern":"Encountered a non-implemented type: (.+?)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/PHPSerialize.mjs","lineNumber":119,"sourceCode":"\n                return `a:${object.length}:{${serializedElements.join(\"\")}}`;\n            } else if (object instanceof Object) {\n                /**\n                 * Objects\n                 * Note: the output cannot be guaranteed to be in the same order as the input\n                 */\n                const serializedElements = [];\n                const keys = Object.keys(object);\n\n                for (const key of keys) {\n                    serializedElements.push(`${serialize(key)}${serialize(object[key])}`);\n                }\n\n                return `a:${keys.length}:{${serializedElements.join(\"\")}}`;\n            }\n\n            /** This should be unreachable */\n            throw new OperationError(`Encountered a non-implemented type: ${typeof object}`);\n        }\n\n        return serialize(input);\n    }\n}\n\nexport default PHPSerialize;\n","sourceCodeStart":101,"sourceCodeEnd":127,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/PHPSerialize.mjs#L101-L127","documentation":"The top-level serialize() function handles null, primitives (via serializeBasicTypes), Arrays, and plain Objects. This 'should be unreachable' throw fires for any value that is not null, not a primitive, not an Array, and not a plain Object — e.g., a Symbol-wrapped object, a Map, a Set, or a class instance that is not caught by instanceof Object.","triggerScenarios":"Input JSON contains values whose typeof is 'object' but that are not instances of Object or Array — e.g., a Map, Set, or a non-standard object created with Object.create(null). A Symbol or function value whose typeof is neither 'object' nor a handled primitive type.","commonSituations":"JSON.parse with a reviver that returns Map or Set instances. Programmatic invocation with data structures containing Symbol or function values. Data mutated after parsing to include non-JSON types.","solutions":["Ensure the input is plain JSON-compatible data: only null, booleans, numbers, strings, arrays, and plain objects","Convert Map/Set instances to plain objects or arrays before serializing","Run JSON.parse(JSON.stringify(data)) to strip non-standard types before calling the operation"],"exampleFix":"// before\nconst data = { items: new Map([['a', 1]]) };\n// after\nconst data = { items: Object.fromEntries(new Map([['a', 1]])) };","handlingStrategy":"type-guard","validationCode":"// Pre-check: deep-validate that all values are JSON-safe\nfunction isJsonSafe(v) {\n  if (v === null) return true;\n  const t = typeof v;\n  if (t === 'boolean' || t === 'number' || t === 'string') return true;\n  if (t !== 'object') return false;\n  if (Array.isArray(v)) return v.every(isJsonSafe);\n  if (Object.getPrototypeOf(v) !== Object.prototype) return false;\n  return Object.values(v).every(isJsonSafe);\n}","typeGuard":"function isPlainObject(v) {\n  return v !== null && typeof v === 'object' &&\n    (Object.getPrototypeOf(v) === Object.prototype || Object.getPrototypeOf(v) === null);\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 object type — sanitize input to plain JSON types\");\n  } else { throw e; }\n}","preventionTips":["Convert Map/Set instances to plain objects or arrays before input","Strip functions and Symbols from the data structure","Run JSON.parse(JSON.stringify(data)) to normalize to 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"}