Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Cache miss will throw Zend\Serializer\Exception on PHP7 using Zend\Serializer\Adapter\Json #95

Closed
yuripave opened this issue Apr 14, 2016 · 5 comments · Fixed by #96
Closed
Assignees
Labels
Milestone

Comments

@yuripave
Copy link

yuripave commented Apr 14, 2016

Due to zendframework/zend-json#23, Zend\Serializer\Exception will be thrown when cache miss on PHP7 if using Zend\Cache\Storage\Plugin\Serializer with Zend\Serializer\Adapter\Json.

@marc-mabe
Copy link
Member

mh please provide an example code that fails for you.
As the unserialize method should not be called on a cache miss undependable which serializer is in use (if any)

@yuripave
Copy link
Author

yuripave commented Apr 15, 2016

Example code running on latest master bc215ac with PHP 7.0.5.

<?php
require 'vendor/autoload.php';

$cache = \Zend\Cache\StorageFactory::adapterFactory('memcached', ['servers' => ['127.0.0.1']]);
$cache->addPlugin(\Zend\Cache\StorageFactory::pluginFactory('serializer', ['serializer' => 'json']));
$cache->getItem('cacheMiss');
$ php -v
PHP 7.0.5 (cli) (built: Apr  8 2016 12:16:01) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans
$ php zend-cache#95.php
PHP Fatal error:  Uncaught Zend\Json\Exception\RuntimeException: Decoding failed: Syntax error in /path/to/zend-cache/vendor/zendframework/zend-json/src/Json.php:68
Stack trace:
#0 /path/to/zend-cache/vendor/zendframework/zend-serializer/src/Adapter/Json.php(89): Zend\Json\Json::decode('', 1)
#1 /path/to/zend-cache/src/Storage/Plugin/Serializer.php(72): Zend\Serializer\Adapter\Json->unserialize(NULL)
#2 /path/to/zend-cache/vendor/zendframework/zend-eventmanager/src/EventManager.php(271): Zend\Cache\Storage\Plugin\Serializer->onReadItemPost(Object(Zend\Cache\Storage\PostEvent))
#3 /path/to/zend-cache/vendor/zendframework/zend-eventmanager/src/EventManager.php(143): Zend\EventManager\EventManager->triggerListeners(Object(Zend\Cache\Storage\PostEvent))
#4 /path/to/zend-cache/src/Storage/Adapter/AbstractAdapter.php(221): Zend\EventManager\EventManager->triggerEvent(Object(Zend\Cache\Storage\PostEvent))
#5 /path/to/zend-cache/src/Stora in /path/to/zend-cache/vendor/zendframework/zend-serializer/src/Adapter/Json.php on line 93

@marc-mabe
Copy link
Member

@yuripave The serializer plugin was trying to unserialize values of missing items (NULL). I thought that is not the case but it is and it's a bug of zend-cache. It just was not realized because the serializer was returning the input value untouched in this case (which in my opinion is also wrong)

Please try #96 if that works for you. Thanks!

@yuripave
Copy link
Author

Tested and works great, thanks!
Will this backport to 2.4 as well since it's LTS?

@weierophinney
Copy link
Member

Will this backport to 2.4 as well since it's LTS?

No. We only backport security fixes, and fixes for issues that were regressions introduced by the 2.4 series itself.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants