Skip to content

Fix Array to string conversion warning in AltSessions.php#766

Open
austinginder wants to merge 1 commit intoCleanTalk:masterfrom
austinginder:fix-altsessions-array-warning
Open

Fix Array to string conversion warning in AltSessions.php#766
austinginder wants to merge 1 commit intoCleanTalk:masterfrom
austinginder:fix-altsessions-array-warning

Conversation

@austinginder
Copy link
Copy Markdown

Summary

Fixes #765

When a cookie value is an array and the expected type annotation is string, the (string)$value cast on line 227 triggers a PHP "Array to string conversion" warning on every POST /wp-json/cleantalk-antispam/v1/alt_sessions request.

Change

Added an is_array() check before the cast. Array values are JSON-encoded via wp_json_encode() instead of cast directly.

// Before
$cookies_array[$name] = (string)$value;

// After
$cookies_array[$name] = is_array($value) ? wp_json_encode($value) : (string)$value;

When a cookie value is an array and the expected type is 'string',
the (string) cast triggers a PHP warning. Add an is_array() check
to JSON-encode array values before storing.

Fixes CleanTalk#765
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Array to string conversion warning in AltSessions.php line 227

1 participant