Issues

ZF2-133: CLONE - Zend_Cache_Core::save() requires that $data be a string or that it be auto-serialized

Issue Type: Improvement Created: 2012-01-09T19:11:32.000+0000 Last Updated: 2012-01-09T19:18:09.000+0000 Status: Closed Fix version(s): Reporter: Marc Bennewitz (private) (mabe) Assignee: Marc Bennewitz (private) (mabe) Tags: - Zend\Cache

Related issues: Attachments:

Description

Trying to store and integer or an object throws a fatal exception even when using a cache backend that supports a large range of values. Memcache and APC can store complete objects and they do not need to be pre-serialized for those backends. It is generally wise to wrap data in an object prior to storing it because otherwise arrays are mangled in certain circumstances.

Checking the validity of the passed dat should be the domain of the backend, not the front-end. The front-end has no way of knowing which data is valid for a particular backend. As mentioned, Memcache and APC have no trouble dealing with complex objects or arrays. In any case, storing an integer should be reasonable.

Lines 276-283 from Zend_Cache_Core:

<pre class="highlight"> 
        if ($this->_options['automatic_serialization']) {
            // we need to serialize datas before storing them
            $data = serialize($data);
        } else {
            if (!is_string($data)) {
                Zend_Cache::throwException("Datas must be string or set automatic_serialization = true");
            }
        }

Test code to demonstrate the problem:

<pre class="highlight">
$frontendOptions = array(
    'caching' => true,
    'logging' => false,
    'lifetime' => 3600,
    'automatic_cleaning_factor' => 0,
);
$backendOptions = array(
    'servers' => array(array('host' => 'localhost', 'port' => 11211, 'persistent' => false)),
    'compression' => true,
);
$cache = Zend_Cache::factory('Core', 'Memcached', $frontendOptions, $backendOptions);
$cache->save(1, 'test_cache');

Comments

Posted by Marc Bennewitz (private) (mabe) on 2012-01-09T19:18:09.000+0000

fixed by desing

Now data no longer gets serialized by default. To enable serializing please use the plug-in "serializer"

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts