Skip to content

Array to string conversion warning in AltSessions.php line 227 #765

@austinginder

Description

@austinginder

Plugin version: 6.75
PHP version: 8.1 / 8.3
WordPress version: 6.x

Description

AltSessions.php:227 triggers an "Array to string conversion" warning when $value is an array and the type annotation is string.

The warning fires on every POST /wp-json/cleantalk-antispam/v1/alt_sessions request where the cookie value happens to be an array.

Steps to reproduce

  1. Visit a page with CleanTalk active
  2. A POST /wp-json/cleantalk-antispam/v1/alt_sessions request fires
  3. If any cookie value is an array, the (string)$value cast on line 227 triggers the warning

Location

lib/Cleantalk/ApbctWP/Variables/AltSessions.php, line 227:

case 'string':
    $cookies_array[$name] = (string)$value;
    break;

Suggested fix

Check if $value is an array before casting:

case 'string':
    $cookies_array[$name] = is_array($value) ? wp_json_encode($value) : (string)$value;
    break;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions