{"record":{"id":"fd6b52d71b081eaf","repo":"moodle/moodle","slug":"could-not-determine-cftype-for-gettype-value","errorCode":null,"errorMessage":"Could not determine CFType for '. gettype($value)","messagePattern":"Could not determine CFType for '\\. gettype\\(\\$value\\)","errorType":"validation","errorClass":"PListException","httpStatus":null,"severity":"error","filePath":"public/lib/plist/src/CFPropertyList/CFTypeDetector.php","lineNumber":235,"sourceCode":"                }\n\n                return new CFNumber($value);\n            break;\n\n            case is_string($value):\n                if (strpos($value, \"\\x00\") !== false) {\n                    return new CFData($value);\n                }\n                return new CFString($value);\n\n            break;\n\n            default:\n                if ($this->suppressExceptions) {\n                    return $this->defaultValue();\n                }\n\n                throw new PListException('Could not determine CFType for '. gettype($value));\n            break;\n        }\n    }\n}\n","sourceCodeStart":217,"sourceCodeEnd":240,"githubUrl":"https://github.com/moodle/moodle/blob/48ea8c33227277e916cdd4079dbecef448b37f2c/public/lib/plist/src/CFPropertyList/CFTypeDetector.php#L217-L240","documentation":"The catch-all case in CFTypeDetector::toCFType(): the value's PHP type (gettype()) matched no supported case, so no CFType could be determined. Thrown as PListException when suppressExceptions is false.","triggerScenarios":"Passing values of types outside the detector's switch: typically null when the detector was constructed without a defaultValue, or exotic types like a closed resource/unknown type returned from an extension.","commonSituations":"Arrays containing null entries fed to CFPropertyList::detect(); PHP version changes introducing new internal types; data from external sources (API/DB) containing unexpected nulls.","solutions":["Filter or replace null entries before detection (array_filter with a callback keeping meaningful values).","Set a default: new CFTypeDetector(['suppressExceptions' => true]) plus a sensible defaultValue so nulls map to it.","Sanitize input data recursively to only scalars/arrays before calling detect()."],"exampleFix":"// before\n$plist->detect(['a' => null]); // PListException\n// after\n$detector = new CFTypeDetector(['suppressExceptions' => true]);\n$plist->detect(['a' => $value ?? '']);","handlingStrategy":"validation","validationCode":"function sanitizeForPlist(array $data): array {\n  array_walk_recursive($data, function (&$v) {\n    if ($v === null) { $v = ''; }\n    elseif (!is_scalar($v) && !is_array($v)) { $v = (string) $v; }\n  });\n  return $data;\n}","typeGuard":"if ($value === null || (!is_scalar($value) && !is_array($value))) { $value = ''; }","tryCatchPattern":"try { $plist->detect($data); }\ncatch (PListException $e) { error_log($e->getMessage()); $plist->detect(sanitizeForPlist($data)); }","preventionTips":["Normalize nulls to '' or omit keys before detection","Construct CFTypeDetector with suppressExceptions=true and a meaningful defaultValue","Re-sanitize data from external sources (APIs, DB) before plist conversion"],"tags":["plist","php","type-detection","null"],"backgroundTag":"null-argument","analyzedSha":"48ea8c33227277e916cdd4079dbecef448b37f2c","analyzedAt":"2026-09-14T20:34:48.527Z","contentChangedAt":"2026-09-14T20:34:48.527Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}