Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Serialize.php
Go to the documentation of this file.
1 <?php
7 
9 
15 {
19  public function serialize($data)
20  {
21  if (is_resource($data)) {
22  throw new \InvalidArgumentException('Unable to serialize value.');
23  }
24  return serialize($data);
25  }
26 
30  public function unserialize($string)
31  {
32  if (false === $string || null === $string || '' === $string) {
33  throw new \InvalidArgumentException('Unable to unserialize value.');
34  }
35  set_error_handler(
36  function () {
37  restore_error_handler();
38  throw new \InvalidArgumentException('Unable to unserialize value, string is corrupted.');
39  },
40  E_NOTICE
41  );
42  $result = unserialize($string, ['allowed_classes' => false]);
43  restore_error_handler();
44  return $result;
45  }
46 }