serialize.phpt 826 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. --TEST--
  2. GMP serialization and unserialization
  3. --SKIPIF--
  4. <?php if (!extension_loaded("gmp")) print "skip"; ?>
  5. --FILE--
  6. <?php
  7. var_dump($n = gmp_init(42));
  8. var_dump($s = serialize($n));
  9. var_dump(unserialize($s));
  10. $n = gmp_init(13);
  11. $n->foo = "bar";
  12. var_dump(unserialize(serialize($n)));
  13. try {
  14. unserialize('C:3:"GMP":0:{}');
  15. } catch (Exception $e) { var_dump($e->getMessage()); }
  16. try {
  17. unserialize('C:3:"GMP":8:{s:2:"42";}');
  18. } catch (Exception $e) { var_dump($e->getMessage()); }
  19. ?>
  20. --EXPECTF--
  21. object(GMP)#%d (1) {
  22. ["num"]=>
  23. string(2) "42"
  24. }
  25. string(30) "C:3:"GMP":15:{s:2:"42";a:0:{}}"
  26. object(GMP)#%d (1) {
  27. ["num"]=>
  28. string(2) "42"
  29. }
  30. object(GMP)#%d (2) {
  31. ["foo"]=>
  32. string(3) "bar"
  33. ["num"]=>
  34. string(2) "13"
  35. }
  36. string(28) "Could not unserialize number"
  37. string(32) "Could not unserialize properties"