Problem/Motivation

Warning: Array to string conversion in panels_cache_object->cache() (line 158 of /mnt/www/html/jnjnab4d1dev8/docroot/profiles/jjbos/modules/contrib/panels/includes/plugins.inc).

Steps to reproduce

  1. Open the main application page.
  2. Log in as admin.
  3. Go to /admin/structure/pages.
  4. Click on the 'Edit' link in a row of any existing panel page.
  5. Click on the 'Content' link.
  6. Click on the gear icon near one of the blocks.
  7. Click on Caching->Change.
  8. Click on the 'Simple Cache' radio button and click 'Next'.
  9. Select '15 sec' in Lifetime and click the "Save' button.
  10. Click on the 'Update and Save' button.
  11. Go to /admin/config/development/performance.
  12. Click on the 'Clear all caches' button.
  13. Go to a page from step 4.

Proposed resolution

Here is a commit - https://git.drupalcode.org/project/panels/-/commit/13c4dc1492a74e3dd82c3...
introduced the issue ( 11 year ago, during migration from Drupal 6 to Drupal 7, possibly)

-    $this->head = str_replace($this->head, '', drupal_set_html_head());
+   $this->head = str_replace($this->head, '', drupal_add_html_head());

The first problem: drupal_set_html_head always returns a string, and str_replace makes sense.
drupal_add_html_head always returns an array, and the sense is not as clear as before.

Second problem in function restore:

  function restore() {
    if (!empty($this->head)) {
   -   drupal_set_html_head($this->head);
   +   drupal_add_html_head($this->head);

Before change it made sense, because inside drupal_set_html_head we did $stored_head .= $data ."\n";
After the change this line is useless, because drupal_add_html_head withour $key param will not add anything

Remaining tasks

First issue should be fixed by MR ( it is as much close as possible to initial behaviour, in my view)

As a solution for second problem we just might just remove the

    if (!empty($this->head)) {
      drupal_add_html_head($this->head);
    }

from restore function

CommentFileSizeAuthor
#7 php_8.0_compatibility_fix-3292020.patch512 bytespatelh84

Issue fork panels-3292020

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

driverok created an issue. See original summary.

driverok’s picture

Title: Array to string conversion in panels_cache_object->cache()' warnings present on the page » Array to string conversion in panels_cache_object->cache() warnings present on the page

driverok’s picture

Issue summary: View changes
renat33’s picture

Hello,

I've checked the issue using STR from description on PHP - 8.0.16, Drupal - 7.89.
The issue is fixed. There are no 'Array to string conversion in panels_cache_object->cache()' warnings on the page.

Best Regards

cafuego’s picture

The warning is definitely present with PHP 8.1.

patelh84’s picture

StatusFileSize
new512 bytes

I am adding a patch which I have tested on my local and is working for me. After applying it the warnings are not displayed on the pages.

Holka_a’s picture

Status: Active » Needs review

Patch Patch worked for me, thanks.

BrijeshParmar’s picture

Status: Needs review » Reviewed & tested by the community

The patch #7 work fine for me.

joelpittet made their first commit to this issue’s fork.

joelpittet’s picture

I had to prove to myself the array_diff_key was what we are doing here... as it appears we should be doing the same as what the CSS/JS is doing.
https://3v4l.org/Y3aoM

Thanks for that elegant solution @driverok

Changed the init value but it's always an array and removed the is_array check because it's always true... now, I addressed the second part of this issue which was the restore function.

I hope by finally making this "work" the way it was intended, it doesn't break something...

  • joelpittet committed 46b9f4d on 7.x-3.x authored by driverok
    Issue #3292020 by driverok, joelpittet, patelh84, Holka_a, renat33,...
joelpittet’s picture

Status: Reviewed & tested by the community » Fixed
joelpittet’s picture

Adding to the release plan #3157069: Plan for Panels 7.x-3.11

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.