dolibarr/test/other/test_serialize.php

63 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2020-03-04 01:54:02 +01:00
#!/usr/bin/env php
<?php
$path = __DIR__ . '/';
2021-06-29 16:33:53 +02:00
2020-03-04 01:54:02 +01:00
$res=@include_once $path.'/../htdocs/master.inc.php';
2021-06-29 16:33:53 +02:00
$res=@include_once $path.'/../../htdocs/master.inc.php';
2023-12-04 11:22:28 +01:00
if (! $res) {
@include_once '../../master.inc.php';
}
if (! $res) {
@include_once '../master.inc.php';
}
if (! $res) {
@include_once './master.inc.php';
}
2020-03-04 01:54:02 +01:00
include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
// Generate an object sample
$object = new stdClass();
$object->aaa = 'aaa';
$object->bbb = 'bbb';
$object->thirdparty = new stdClass();
$tmp = new Societe($db);
$tmp->name = 'MyBigCompany';
2021-03-01 11:26:00 +01:00
foreach ($tmp as $key => $value) {
2020-03-04 01:54:02 +01:00
if (!in_array($key, array(
'name', 'name_alias', 'ref_ext', 'address', 'zip', 'town', 'state_code', 'country_code'
2021-03-01 11:26:00 +01:00
))) {
continue; // Discard if not into a dedicated list
}
2023-12-04 11:22:28 +01:00
if (!is_object($value)) {
$object->thirdparty->{$key} = $value;
}
2020-03-04 01:54:02 +01:00
}
// Show information
print "\n";
print "*** PHP Version : ".PHP_VERSION." - Dolibarr Version : ".DOL_VERSION."\n";
print "*** print_r() of object used to generate the key to hash for blockedlog on the object sample:\n";
print print_r($object, true);
print "*** We build hash(256) of this string:\n";
print hash('sha256', print_r($object, true));
print "\n";
print "*** When it is serialized() to store in db, we got:\n";
print serialize($object);
print "\n";
print "*** And when it is print_r(unserialized()) to reuse it:\n";
print print_r(unserialize(serialize($object)), true);
print "*** We build hash(256) of this string:\n";
print hash('sha256', print_r(unserialize(serialize($object)), true));
print "\n";
print "\n";
//print print_r(unserialize(serialize($object)));