File indexing completed on 2025-01-26 05:25:25
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Serializer 0017 * @subpackage Adapter 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** @see Zend_Serializer_Adapter_AdapterAbstract */ 0024 // require_once 'Zend/Serializer/Adapter/AdapterAbstract.php'; 0025 0026 /** 0027 * @category Zend 0028 * @package Zend_Serializer 0029 * @subpackage Adapter 0030 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0031 * @license http://framework.zend.com/license/new-bsd New BSD License 0032 */ 0033 class Zend_Serializer_Adapter_PhpCode extends Zend_Serializer_Adapter_AdapterAbstract 0034 { 0035 /** 0036 * Serialize PHP using var_export 0037 * 0038 * @param mixed $value 0039 * @param array $opts 0040 * @return string 0041 */ 0042 public function serialize($value, array $opts = array()) 0043 { 0044 return var_export($value, true); 0045 } 0046 0047 /** 0048 * Deserialize PHP string 0049 * 0050 * Warning: this uses eval(), and should likely be avoided. 0051 * 0052 * @param string $code 0053 * @param array $opts 0054 * @return mixed 0055 * @throws Zend_Serializer_Exception on eval error 0056 */ 0057 public function unserialize($code, array $opts = array()) 0058 { 0059 $eval = @eval('$ret=' . $code . ';'); 0060 if ($eval === false) { 0061 $lastErr = error_get_last(); 0062 // require_once 'Zend/Serializer/Exception.php'; 0063 throw new Zend_Serializer_Exception('eval failed: ' . $lastErr['message']); 0064 } 0065 return $ret; 0066 } 0067 }