Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Serializer / Adapter / PhpCode.php
blob6e484ad7dc48f161b5e9f25543807fa028bc998a
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Serializer\Adapter;
12 use Zend\Serializer\Exception;
13 use Zend\Stdlib\ErrorHandler;
15 class PhpCode extends AbstractAdapter
17 /**
18 * Serialize PHP using var_export
20 * @param mixed $value
21 * @return string
23 public function serialize($value)
25 return var_export($value, true);
28 /**
29 * Deserialize PHP string
31 * Warning: this uses eval(), and should likely be avoided.
33 * @param string $code
34 * @return mixed
35 * @throws Exception\RuntimeException on eval error
37 public function unserialize($code)
39 ErrorHandler::start(E_ALL);
40 $ret = null;
41 // This suppression is due to the fact that the ErrorHandler cannot
42 // catch syntax errors, and is intentionally left in place.
43 $eval = @eval('$ret=' . $code . ';');
44 $err = ErrorHandler::stop();
46 if ($eval === false || $err) {
48 $msg = 'eval failed';
50 // Error handler doesn't catch syntax errors
51 if ($eval === false) {
52 $lastErr = error_get_last();
53 $msg .= ': ' . $lastErr['message'];
56 throw new Exception\RuntimeException($msg, 0, $err);
59 return $ret;