Array to string conversion in execute-cache.php:1039 (breeze_commented_posts)
-
Hello,
We see this warning in the PHP error log of a site running Breeze 2.6.1 (it was the same on 2.6.0):
PHP Warning: Array to string conversion in .../wp-content/plugins/breeze/inc/cache/execute-cache.php on line 1039Cause:
Breeze_Execute_Cache::get_wp_logged_in_cookie_value()loops over every cookie and casts the value to a string before checking the cookie name:foreach ( $_COOKIE as $cookie_name => $cookie_value ) { $cookie_name = (string) $cookie_name; $cookie_value = (string) $cookie_value; // line 1039 // the wordpress_logged_in_ name check comes only after thisBreeze itself sets the cookie
breeze_commented_posts[<post_id>]for visitors who left a comment (inc/cache/purge-cache.php, line 174), and reads it back as an array inexecute-cache.php(line 977). PHP parses a cookie name with square brackets into an array, so$_COOKIE['breeze_commented_posts']is an array, and the cast on line 1039 raises the warning when such a visitor opens a page.Steps to reproduce:
- Enable page cache in Breeze.
- Leave a comment as a guest on any post, so the browser gets
breeze_commented_posts[123]. - Open any page: the warning appears in the PHP error log.
Suggested fix: skip non-string values before the cast, or check the name first, for example:
foreach ( $_COOKIE as $cookie_name => $cookie_value ) { if ( ! is_string( $cookie_value ) ) { continue; } $cookie_name = (string) $cookie_name;The value of such a cookie can never be a
wordpress_logged_in_cookie anyway, so skipping it does not change the behaviour of the check.Thank you.
You must be logged in to reply to this topic.