-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix the issue where if CRedisCache's getValue method returns null, causing deprecation message when passed to unserialize #4496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This will fix deprecation warning of passing null to parameter yiisoft#1 of type string to unserialize function (PHP 8.1)
|
|
This may change behavior when serializer is disabled in cache component.
How to reproduce this bug? If key is set by cache component, it should always be generated using |
|
Related to #4497? |
|
@rob006 to reproduce this, create a small yii app that caches values to redis. clear that cache etc. I don't understand the mechanics of the CRedisCache parseResponse method, but it seems valid for it to return a null value under some circumstances which getValue would pass on to its caller. As getValue is expected to return either a string or a boolean - not null - adding this simple guard clause will prevent this unexpected/illegal return value from being passed up the stack. |
Yes. This could also be fixed more generally by adding a guard clause to CCache's mget and get methods but fixing it in CRedisCache's getValue method minimizes the amount of code that needs to be changed for when the cache backend is redis. |
|
Related fixes in Yii 2: |
Fix the issue where if CRedisCache's getValue method returns null then CCache get method may pass a null value to unserialize function causing a deprecation message to be raised. See the stack trace below.
This occurs with PHP 8.1.
2022/11/28 16:41:48 [error] [php] unserialize(): Passing null to parameter #1 ($data) of type string is deprecated (/var/www/project/vendor/yiisoft/yii/framework/caching/CCache.php:108)
Stack trace:
#0 /var/www/project/vendor/yiisoft/yii/framework/caching/CCache.php(108): unserialize()
#1 /var/www/project/vendor/yiisoft/yii/framework/yiilite.php(3160): CRedisCache->get()
#2 /var/www/project/vendor/yiisoft/yii/framework/yiilite.php(3151): UrlManager->processRules()
#3 /var/www/project/vendor/yiisoft/yii/framework/yiilite.php(1104): UrlManager->init()
#4 /var/www/project/vendor/yiisoft/yii/framework/yiilite.php(1393): CWebApplication->getComponent()
#5 /var/www/project/vendor/yiisoft/yii/framework/yiilite.php(1716): CWebApplication->getUrlManager()
#6 /var/www/project/vendor/yiisoft/yii/framework/yiilite.php(1236): CWebApplication->processRequest()
#7 /var/www/project/index.php(42): CWebApplication->run()