test_serialize.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env php
  2. <?php
  3. $path = __DIR__ . '/';
  4. $res=@include_once $path.'/../htdocs/master.inc.php';
  5. $res=@include_once $path.'/../../htdocs/master.inc.php';
  6. if (! $res) @include_once '../../master.inc.php';
  7. if (! $res) @include_once '../master.inc.php';
  8. if (! $res) @include_once './master.inc.php';
  9. include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  10. // Generate an object sample
  11. $object = new stdClass();
  12. $object->aaa = 'aaa';
  13. $object->bbb = 'bbb';
  14. $object->thirdparty = new stdClass();
  15. $tmp = new Societe($db);
  16. $tmp->name = 'MyBigCompany';
  17. foreach ($tmp as $key => $value) {
  18. if (!in_array($key, array(
  19. 'name', 'name_alias', 'ref_ext', 'address', 'zip', 'town', 'state_code', 'country_code'
  20. ))) {
  21. continue; // Discard if not into a dedicated list
  22. }
  23. if (!is_object($value)) $object->thirdparty->{$key} = $value;
  24. }
  25. // Show information
  26. print "\n";
  27. print "*** PHP Version : ".PHP_VERSION." - Dolibarr Version : ".DOL_VERSION."\n";
  28. print "*** print_r() of object used to generate the key to hash for blockedlog on the object sample:\n";
  29. print print_r($object, true);
  30. print "*** We build hash(256) of this string:\n";
  31. print hash('sha256', print_r($object, true));
  32. print "\n";
  33. print "*** When it is serialized() to store in db, we got:\n";
  34. print serialize($object);
  35. print "\n";
  36. print "*** And when it is print_r(unserialized()) to reuse it:\n";
  37. print print_r(unserialize(serialize($object)), true);
  38. print "*** We build hash(256) of this string:\n";
  39. print hash('sha256', print_r(unserialize(serialize($object)), true));
  40. print "\n";
  41. print "\n";
  42. //print print_r(unserialize(serialize($object)));