unserialize(): Passing null to parameter #1 ($data) of type string is deprecated
Opened this issue · 0 comments
✏️ Describe the bug
It's not a bug, just a warning.
When a settings class can't be found in the cache null
as default value will be returned to unserialize()
https://github.com/spatie/laravel-settings/blob/main/src/SettingsCache.php#L55. Since PHP8.1 unserialize()
shows a deprecation warning: unserialize(): Passing null to parameter #1 ($data) of type string is deprecated
.
↪️ To Reproduce
Provide us a pest test like this one which shows the problem:
use Spatie\LaravelSettings\Settings;
use Spatie\LaravelSettings\Support\SettingsCacheFactory;
$cache = app(SettingsCacheFactory::class)->build(Settings::repository());
$cache->clear();
$cache->get(Settings::class);
Laravel's logging of deprecation warnings should be enabled https://laravel.com/docs/10.x/logging#logging-deprecation-warnings
Maybe a string cast or a check should prevent this behaviour:
$settings = unserialize((string) $serialized);
✅ Expected behavior
No deprecation warning.
🖥️ Versions
Laravel: 10.48.19
Laravel settings: 3.4.0
PHP: 8.3