php-src/ext/gmp/tests/serialize.phpt
Nikita Popov 4218e89f8d Fix bug #65997 by switching to Serializable for GMP
Rather than using get_properties and __wakeup for serialization
the code now uses Serializable::serialize() and
Serializable::unserialize(). The get_properties handler is switched
to a get_debug_info handler. Thus get_gc will now return only
the normal properties and not do any modifications, thus fixing
the leak. This also avoids a $num property from being publicly
visible after the object was dumped or serialized, so that's an
extra plus.
2013-10-29 20:58:30 +01:00

43 lines
825 B
PHP

--TEST--
GMP serialization and unserialization
--SKIPIF--
<?php if (!extension_loaded("gmp")) print "skip"; ?>
--FILE--
<?php
var_dump($n = gmp_init(42));
var_dump($s = serialize($n));
var_dump(unserialize($s));
$n = gmp_init(13);
$n->foo = "bar";
var_dump(unserialize(serialize($n)));
try {
unserialize('C:3:"GMP":0:{}');
} catch (Exception $e) { var_dump($e->getMessage()); }
try {
unserialize('C:3:"GMP":8:{s:2:"42"}');
} catch (Exception $e) { var_dump($e->getMessage()); }
?>
--EXPECTF--
object(GMP)#%d (1) {
["num"]=>
string(2) "42"
}
string(30) "C:3:"GMP":15:{s:2:"42";a:0:{}}"
object(GMP)#%d (1) {
["num"]=>
string(2) "42"
}
object(GMP)#%d (2) {
["foo"]=>
string(3) "bar"
["num"]=>
string(2) "13"
}
string(28) "Could not unserialize number"
string(32) "Could not unserialize properties"