PHP Deprecated: unserialize()

Hi there,
Does anyone else gets this php error log error when using php 8.1 ?
PHP Deprecated: unserialize(): Passing null to parameter #1 ($data) of type string is deprecated in …/app/functions/fn.products.php on line 2850
That i with the latest cs-cart 4.18.1

Thank you for your report. I was able to reproduce this issue and passed it to the developers.

This issue was fixed and the fix will be included into the version 4.19.1.

I just noticed there are 409,000 errors in my php log since Sept. 2024 that are the same as this except on line 2857. Using csc 4.18.3, php v8.1.

Is there fix for this yet?

Please provide a full description of the error log entry you are referring to.

Here is a line from my error log file:

[03-May-2025 06:16:17 America/New_York] PHP Deprecated:  unserialize(): Passing null to parameter #1 ($data) of type string is deprecated in /home2/donstren/public_html/app/functions/fn.products.php on line 2857

The other 400k lines are the same except for the date/time.

The function is:
function fn_get_products_layout($params)
and line 2857 is:
$category_views = unserialize($_layout['selected_views']);

Can I safely replace that line with the following?:

    try {
          $category_views = unserialize($_layout['selected_views']);
    } catch (Error $e) {
          $category_views = array();
   }

Thank you for your reply. To be honest, I can’t imagine how this error could even be possible.

Does the code in your installation look exactly like this?

2851    if (!empty($params['category_id'])) {
2852        $_layout = db_get_row(
2853            "SELECT default_view, selected_views FROM ?:categories WHERE category_id = ?i",
2854            $params['category_id']
2855        );
2856        $category_default_view = $_layout['default_view'];
2857        $category_views = unserialize($_layout['selected_views']);

What database management system are you using (MySQL / MariaDB / something else), what version is it, and what database_backend is set up in the config.local.php file of your installation?

Yes, the existing code looks exactly like that.
Using MySQL.

Database backend in config.local.php is mysqli:
$config['database_backend'] = 'mysqli';

MySQL version is 8.0.4.2

Php version is 8.1

Above, in this thread, it says the issue was reproduced and fixed and will be included in 4.19.1. But, since that hasn’t been released yet, doesn’t it make sense that I have the error?

If you want me to run some test/validation code, just let me know.

Thank you for the reply.

Yes, my fault. Even if I failed to reproduce this issue, it is indeed the same error and it has indeed been fixed.

Please replace:

        $category_views = unserialize($_layout['selected_views']);

with:

        $category_views = !empty($_layout['selected_views']) ? unserialize($_layout['selected_views']) : [];

And yes, the fix will be included in 4.19.1.

1 Like

No problem. Thanks for sticking with it and sending the fix!

I made the change, tested it, and there are no more errors in the log. Thanks again!

1 Like