mirror of
https://github.com/php/php-src.git
synced 2026-04-24 08:28:26 +02:00
17ceed9ae7
GMP directly implements internal serialize/unserialize handlers rather than going through the Serializable interface, so it ended up being missed when adding the new __serialize()/__unserialize() methods to other classes. The serialization format is similar to before, but uses hex instead of decimal encoding and omits the members if not used (which should be almost always).
71 lines
1.5 KiB
PHP
71 lines
1.5 KiB
PHP
--TEST--
|
|
GMP serialization and unserialization
|
|
--EXTENSIONS--
|
|
gmp
|
|
--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($s = serialize($n));
|
|
var_dump(unserialize($s));
|
|
|
|
var_dump(unserialize('C:3:"GMP":15:{s:2:"42";a:0:{}}'));
|
|
|
|
try {
|
|
unserialize('C:3:"GMP":0:{}');
|
|
} catch (Exception $e) { var_dump($e->getMessage()); }
|
|
|
|
try {
|
|
unserialize('C:3:"GMP":9:{s:2:"42";}');
|
|
} catch (Exception $e) { var_dump($e->getMessage()); }
|
|
|
|
try {
|
|
unserialize('O:3:"GMP":0:{}');
|
|
} catch (Exception $e) { var_dump($e->getMessage()); }
|
|
|
|
try {
|
|
unserialize('O:3:"GMP":1:{i:0;i:0;}');
|
|
} catch (Exception $e) { var_dump($e->getMessage()); }
|
|
|
|
try {
|
|
unserialize('O:3:"GMP":1:{i:0;s:0:"";}');
|
|
} catch (Exception $e) { var_dump($e->getMessage()); }
|
|
|
|
try {
|
|
unserialize('O:3:"GMP":2:{i:0;s:1:"0";i:1;i:0;}');
|
|
} catch (Exception $e) { var_dump($e->getMessage()); }
|
|
|
|
?>
|
|
--EXPECTF--
|
|
object(GMP)#%d (1) {
|
|
["num"]=>
|
|
string(2) "42"
|
|
}
|
|
string(27) "O:3:"GMP":1:{i:0;s:2:"2a";}"
|
|
object(GMP)#%d (1) {
|
|
["num"]=>
|
|
string(2) "42"
|
|
}
|
|
string(56) "O:3:"GMP":2:{i:0;s:1:"d";i:1;a:1:{s:3:"foo";s:3:"bar";}}"
|
|
object(GMP)#%d (2) {
|
|
["foo"]=>
|
|
string(3) "bar"
|
|
["num"]=>
|
|
string(2) "13"
|
|
}
|
|
object(GMP)#1 (1) {
|
|
["num"]=>
|
|
string(2) "42"
|
|
}
|
|
string(28) "Could not unserialize number"
|
|
string(32) "Could not unserialize properties"
|
|
string(28) "Could not unserialize number"
|
|
string(28) "Could not unserialize number"
|
|
string(28) "Could not unserialize number"
|
|
string(32) "Could not unserialize properties"
|