kphp
kphp copied to clipboard
msgpack serialization of interfaces
_main();
function _main() {
/** @var I $i */
$i = new A(42);
instance_serialize($i);
}
interface I {}
/** @kphp-serializable */
class A implements I{
/** @kphp-serialized-field 1 */
private int $x;
public function __construct(int $x) {
$this->x = $x;
}
}
This code's compilation fails with
Compilation error at stage: Apply phpdocs, gen by parse-and-apply-phpdoc.cpp:677
kphp_script_dummy.php:17
interface I {}
@kphp-serialize is allowed only for classes
Serialization of interfaces if forbidden, because serialization doesn't store any class-ID of the serialized object and so can not be deserialized.
Probably for interfaces we can allow some overhead and store class name in serialization result too.