Expand description
serialize, unserialize and var_export, in PHP 8.5’s formats.
| PHP | Rust |
|---|---|
serialize($value) | serialize (Value) |
unserialize($data, ['max_depth' => $n]) | unserialize, Options |
var_export($value, true) | var_export |
warnings unserialize() emits | Unserialized::warnings, Error::Failed |
Values are scalars, arrays and stdClass objects. Floats use
serialize_precision = -1 (d:0.1;, d:1.0E+25;, d:INF;). An
Value::Ext object is written as its Extension::to_array (PHP code
serializes getArrayCopy(), not the object).
unserialize reads every format PHP writes for those values (N, b,
i, d, s, S, a, O/C of stdClass, and the r/R
back-references), with PHP’s error offsets, warnings and depth limit.
Back-references resolve to the value at that slot when they are read,
which is what PHP produces for data serialize writes; Value has no
references or object identity, so they become copies. Objects of other
classes, enums (E:), and back-references to a container that is still
being read (recursive structures) cannot be represented and fail with
Error::Unsupported.
Structs§
- Options
unserialize()options.- Unserialized
- A successful
unserialize(): the value and the warnings PHP emitted (for exampleunserialize(): Extra data starting at offset 4 of 5 bytes).
Enums§
- Error
- Why
unserialize()failed.
Functions§
- serialize
serialize($value): PHP’s byte string.- serialize_
into serialize($value), appended toout.- unserialize
unserialize($data, $options).- var_
export var_export($value, true): PHP source code for the value, as bytes (string contents are copied verbatim).