phpUnserialize function

Object? phpUnserialize(
  1. String data
)

PHP unserialize() of data: arrays whose keys are exactly 0..n-1 in order become a List, other arrays a Map<String, Object?> (integer keys as decimal strings), objects a PhpObject. References (r:, R:) and Serializable payloads (C:) throw FormatException, as does any malformed input.

Implementation

Object? phpUnserialize(String data) {
  final reader = _Reader(utf8.encode(data));
  final value = reader.read();
  if (reader.offset != reader.bytes.length) {
    throw FormatException(
      'Trailing data after the serialized value',
      data,
      reader.offset,
    );
  }
  return value;
}