[DOCS] fixed code comment in one programlisting
[zend/radio.git] / library / Zend / Serializer / Adapter / PhpCode.php
blob0755a74a4945b4040407b13c2329422fbe963735
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
15 * @category Zend
16 * @package Zend_Serializer
17 * @subpackage Adapter
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id$
23 /** @see Zend_Serializer_Adapter_AdapterAbstract */
24 require_once 'Zend/Serializer/Adapter/AdapterAbstract.php';
26 /**
27 * @category Zend
28 * @package Zend_Serializer
29 * @subpackage Adapter
30 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31 * @license http://framework.zend.com/license/new-bsd New BSD License
33 class Zend_Serializer_Adapter_PhpCode extends Zend_Serializer_Adapter_AdapterAbstract
35 /**
36 * Serialize PHP using var_export
38 * @param mixed $value
39 * @param array $opts
40 * @return string
42 public function serialize($value, array $opts = array())
44 return var_export($value, true);
47 /**
48 * Deserialize PHP string
50 * Warning: this uses eval(), and should likely be avoided.
52 * @param string $code
53 * @param array $opts
54 * @return mixed
55 * @throws Zend_Serializer_Exception on eval error
57 public function unserialize($code, array $opts = array())
59 $eval = @eval('$ret=' . $code . ';');
60 if ($eval === false) {
61 $lastErr = error_get_last();
62 require_once 'Zend/Serializer/Exception.php';
63 throw new Zend_Serializer_Exception('eval failed: ' . $lastErr['message']);
65 return $ret;