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.
16 * @package Zend_Serializer
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
23 /** @see Zend_Serializer_Adapter_AdapterAbstract */
24 require_once 'Zend/Serializer/Adapter/AdapterAbstract.php';
28 * @package Zend_Serializer
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
36 * Serialize PHP using var_export
42 public function serialize($value, array $opts = array())
44 return var_export($value, true);
48 * Deserialize PHP string
50 * Warning: this uses eval(), and should likely be avoided.
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']);