moodle/moodle · error · PListException

Could not determine CFType for '. gettype($value)

Error message

Could not determine CFType for '. gettype($value)

What it means

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.

Solutions

  1. Filter or replace null entries before detection (array_filter with a callback keeping meaningful values).
  2. Set a default: new CFTypeDetector(['suppressExceptions' => true]) plus a sensible defaultValue so nulls map to it.
  3. Sanitize input data recursively to only scalars/arrays before calling detect().

Example fix

// before
$plist->detect(['a' => null]); // PListException
// after
$detector = new CFTypeDetector(['suppressExceptions' => true]);
$plist->detect(['a' => $value ?? '']);
Defensive patterns

Strategy: validation

Validate before calling

function sanitizeForPlist(array $data): array {
  array_walk_recursive($data, function (&$v) {
    if ($v === null) { $v = ''; }
    elseif (!is_scalar($v) && !is_array($v)) { $v = (string) $v; }
  });
  return $data;
}

Type guard

if ($value === null || (!is_scalar($value) && !is_array($value))) { $value = ''; }

Try / catch

try { $plist->detect($data); }
catch (PListException $e) { error_log($e->getMessage()); $plist->detect(sanitizeForPlist($data)); }

Prevention

When it happens

Trigger: 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.

Common situations: Arrays containing null entries fed to CFPropertyList::detect(); PHP version changes introducing new internal types; data from external sources (API/DB) containing unexpected nulls.

Related errors


AI-assisted analysis of moodle/moodle@48ea8c3322 (2026-09-14). Data as JSON: /api/errors/fd6b52d71b081eaf. Report an issue: GitHub.

Appendix: source

Thrown at public/lib/plist/src/CFPropertyList/CFTypeDetector.php:235

                }

                return new CFNumber($value);
            break;

            case is_string($value):
                if (strpos($value, "\x00") !== false) {
                    return new CFData($value);
                }
                return new CFString($value);

            break;

            default:
                if ($this->suppressExceptions) {
                    return $this->defaultValue();
                }

                throw new PListException('Could not determine CFType for '. gettype($value));
            break;
        }
    }
}

View on GitHub (pinned to 48ea8c3322)