Arquivos
hhvm/hphp/test/quick/continuation_serialize.php
T
Mike Magruder 8283969d81 Don't serialize cppext instances unless they opt-in, and pass the class name for the debugger
Most CPP extension classes don’t think about serialization, and some require more initialization than the default contractor provides. The result is that on deserialization we end up with a partially initialized object, and undefined behavior after that.

Modified the serializer to emit __PHP_Unserializable_Class instead, and just the class name for the debugger case. Modified the deserializer to create a __PHP_Unserializable_Class, too, if we are given a string with a CPP extension instance in it, so we're safe on both sides. I do not raise a warning; the results are pretty clear, I think, and it's also unlikely that most such warnings could (or should) be corrected. Finally, I also removed the odd behavior of emitting "dummy" classes for Closure and Continuation. I found no use of these in any source tree. Closure had no implementation at all, and Continuation had an implementation that simply raised a fatal on any method call. Thus we can safely assume that even if someone was serializing one of these types, they were receiving an object that was useless to them, or would fatal. So I believe this transformation is safe.
2013-07-23 11:44:16 -07:00

41 linhas
1.1 KiB
PHP

<?hh
// Copyright 2004-present Facebook. All Rights Reserved.
function main() {
// Make new wait handles with valid values.
$srwh = StaticResultWaitHandle::create(42);
$r = $srwh->join();
var_dump($r); // Shows 42 correctly.
$sewh = StaticExceptionWaitHandle::create(new Exception("Hi!"));
try {
$r = $sewh->join();
} catch (Exception $e) {
var_dump($e->getMessage()); // Shows "Hi!" correctly.
}
// Serialize the handles and let them go.
$s1 = serialize($srwh);
$s2 = serialize($sewh);
var_dump($s1);
var_dump($s2);
$srwh = null;
$erwh = null;
// Deserialize the handles in the reverse order, so they lay over
// each other's memory. We want to confirm that all fields are
// initialized correctly and that the destructor does not segfault.
$sewh = unserialize($s2);
var_dump($sewh);
$sewh = null; // Let it go
$srwh = unserialize($s1);
var_dump($srwh);
$srwh = null; // Let it go
// Confirm that we can't deserialize one of these as well.
$c1 = unserialize("O:12:\"Continuation\":0:{}");
var_dump($c1);
}
main();