PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Caching » Cache_Lite » Bug #513

Throws Notice when _automaticSerialization = true

Details

Submitted2004-01-03 21:40 UTC
Fromalan at aardwolfweb dot com
Assignedfab
StatusClosed
PackageCache_Lite
PHP VersionIrrelevant
OSany
Roadmaps(Not assigned)

Comments

[2004-01-03 21:40 UTC] alan at aardwolfweb dot com

Description:
------------
In get(), $data is set to false. When _automaticSerialization is true
and a cache miss occurs get() attempts to unserialize the boolean
value "false" and throws a PHP Notice that the value is not a string.

The fix is to check that $data is a string before unserialize(). Diff is
below. (There's also an incedental tab to space fix in the diff.)

--- Lite.old 2004-01-02 16:13:57.000000000 -0800
+++ Lite.php 2004-01-02 16:30:13.000000000 -0800
@@ -232,7 +232,7 @@
}
}
$this->_refreshTime = time() - $this->_lifeTime;
- }
+ }

/**
* Test if a cache is available and (if yes) return it
@@ -275,7 +275,7 @@
if (($data) and ($this->_memoryCaching)) {
$this->_memoryCacheAdd($this->_file, $data);
}
- if ($this->_automaticSerialization) {
+ if (($this->_automaticSerialization) && (is_string($data)))
{
$data = unserialize($data);
}
return $data;

Reproduce code:
---------------
When error reporting is E_ALL or includes E_NOTICE:

<?php
require_once 'Cache/Lite.php';

$cache =& new Cache(array('automaticSerialization' => true));

$cache->get('test');
?>

Actual result:
--------------
Notice: unserialize(): Argument is not an string
in /usr/share/pear/Cache/Lite.php on line 279

[2004-01-03 21:44 UTC] alan at aardwolfweb dot com

Reproduce code should be:
<?php
require_once 'Cache/Lite.php';

$cache =& new Cache_Lite(array('automaticSerialization' =>
true));

$cache->get('test');
?>

[2004-01-03 22:44 UTC] fab at php dot net

'seems to be ok ! I will apply your patch this week ! Thanks :)

[2004-01-08 17:58 UTC] fab at php dot net

This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pear.php.net.

In case this was a pear.php.net website problem, the change will show
up on the website in short time.

Thank you for the report, and for helping us make PEAR better.

commited thanks ! :)