[DOCS] fixed code comment in one programlisting
[zend/radio.git] / library / Zend / Serializer / Adapter / PhpSerialize.php
blobc0be4a07190927bc673499c6e14598bf9101a2e2
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_PhpSerialize extends Zend_Serializer_Adapter_AdapterAbstract
35 /**
36 * @var null|string Serialized boolean false value
38 private static $_serializedFalse = null;
40 /**
41 * Constructor
43 * @param array|Zend_Config $opts
44 * @return void
46 public function __construct($opts = array())
48 parent::__construct($opts);
50 if (self::$_serializedFalse === null) {
51 self::$_serializedFalse = serialize(false);
55 /**
56 * Serialize using serialize()
58 * @param mixed $value
59 * @param array $opts
60 * @return string
61 * @throws Zend_Serializer_Exception On serialize error
63 public function serialize($value, array $opts = array())
65 $ret = serialize($value);
66 if ($ret === false) {
67 $lastErr = error_get_last();
68 require_once 'Zend/Serializer/Exception.php';
69 throw new Zend_Serializer_Exception($lastErr['message']);
71 return $ret;
74 /**
75 * Unserialize
77 * @todo Allow integration with unserialize_callback_func
78 * @param string $serialized
79 * @param array $opts
80 * @return mixed
81 * @throws Zend_Serializer_Exception on unserialize error
83 public function unserialize($serialized, array $opts = array())
85 // TODO: @see php.ini directive "unserialize_callback_func"
86 $ret = @unserialize($serialized);
87 if ($ret === false && $serialized !== self::$_serializedFalse) {
88 $lastErr = error_get_last();
89 require_once 'Zend/Serializer/Exception.php';
90 throw new Zend_Serializer_Exception($lastErr['message']);
92 return $ret;