Hi guys, I did a backtrace using debug_print_backtrace() and the originating function sending an array to the check_plain function is "content_content_field_content_type_content_types()" which does a "t()" providing the Array on which the "htmlspecialchars()" function fails.

The involved modules (in my case) are a combination of Ctools (6.x-1.7) and Panels (6.x-3.7).

Below I will include the first 6 entries of the backtrace log for anyone who wants it :) I have removed any long strings for easier readability.

#0 check_plain(Array ([nl] => Array (...$data...))) called at [/var/vhosts/website/includes/common.inc:932]
#1 t(Field: @widget_label (@field_name) - @field_type, Array ([@widget_label] => Visibility,[@field_name] => field_ma_visibility,[@field_type] => Array ([nl] => Array ()))) called at [/var/vhosts/website/sites/all/modules/cck/includes/panels/content_types/content_field.inc:40]
#2 content_content_field_content_type_content_types(Array ()) called at [/var/vhosts/website/sites/all/modules/ctools/includes/content.inc:149]
#3 ctools_content_get_subtypes(Array ()) called at [/var/vhosts/website/sites/all/modules/ctools/includes/content.inc:630]
#4 ctools_content_get_available_types(Array (), , Array (), Array ([other] => 1)) called at [/var/vhosts/website/sites/all/modules/panels/includes/common.inc:356]
#5 panels_common_get_allowed_types(panels_page, Array ()) called at [/var/vhosts/website/sites/all/modules/panels/panels.module:1414]

For anyone who also wants to find out where the Array (or not-string) variable comes from on their installation do as follows:

Edit includes/bootstrap.inc around line 842 and add the fragment between "static $php525" and "if (isset($php525)) {" as follows:

function check_plain($text) {
  static $php525;

  if ( !is_string($text) && is_array($text) ) {
    echo "<pre>";
    print_r($text);
    debug_print_backtrace();
    echo "</pre>";
  }
  if (!isset($php525)) {
    $php525 = version_compare(PHP_VERSION, '5.2.5', '>=');
  }
  // We duplicate the preg_match() to validate strings as UTF-8 from
  // drupal_validate_utf8() here. This avoids the overhead of an additional
  // function call, since check_plain() may be called hundreds of times during
  // a request. For PHP 5.2.5+, this check for valid UTF-8 should be handled
  // internally by PHP in htmlspecialchars().
  // @see http://www.php.net/releases/5_2_5.php
  // @todo remove this when support for either IE6 or PHP < 5.2.5 is dropped.

  if ($php525) {
    return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
  }
  return (preg_match('/^./us', $text) == 1) ? htmlspecialchars($text, ENT_QUOTES, 'UTF-8') : '';
}

Have fun debugging.

/Kim

Comments

merlinofchaos’s picture

Status: Active » Closed (won't fix)

[/var/vhosts/website/sites/all/modules/cck/includes/panels/content_types/content_field.inc:40

This is CCK module file ^^

nightlife2008’s picture

Ow sorry, your right Merlinofchaos. My appologies!

*EDIT* Can an administrator move this issue to the CCK module issue-list?

Thank you!

Melissamcewen’s picture

Status: Closed (won't fix) » Active

I'm actually getting "warning: htmlspecialchars() expects parameter 1 to be string, array given in /includes/bootstrap.inc" when I
1. Had a field
2. Included it in a node template in panels
3. Deleted the field
4. Went back to panel page to edit

It went away when I deleted the field from the panel template

thauk’s picture

I'm sorry guys for asking this question but I just don't know where to go. I am getting this same error and I have no idea what to do to fix it. Is there a solution to this problem? Can someone give me some detail on exactly what I need to do?

asb’s picture

Version: 6.x-3.7 » 6.x-3.9
Priority: Critical » Normal

Similar issue when editing a Panels page. Watchdog logs:

./admin/build/pages/nojs/operation/page-hauptseite/handlers/page_hauptseite_panel_context/content
Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (line 1152 of /var/www/drupal/includes/bootstrap.inc).

The offending line in bootstrap.inc is:

function check_plain($text) {
  static $php525;

  if (!isset($php525)) {
    $php525 = version_compare(PHP_VERSION, '5.2.5', '>=');
  }
  if ($php525) {
    return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
  }
  return (preg_match('/^./us', $text) == 1) ? htmlspecialchars($text, ENT_QUOTES, 'UTF-8') : '';
}  

So this directly relates to

#225211: warning: preg_match() expects parameter 2 to be string - SRSLY, WON'T FIX, EVER.

and

#829250: warning: htmlspecialchars() expects parameter 1 to be string, array given in /home/opticist/public_html/includes/bootstrap.inc,

meaning that some module - not necessarily Panels - sends an array as input to check_plain() which isn't permitted and triggers the core error. The core error message won't be fixed because it simply indicates something caused by a contrib module that shouldn't happen. Most fixes flating around seem to do nothing but to mask the error message.

What we need to figure out is what module generates an array instead of a text string. However, after reading through these old issues, I have no idea how and where to put what snippets to do a "backtrace" (some instructions reference to Drupal 5, others require the 'Devel' module), so I'm stuck here.

If I'm adding this snippet, as suggest in the original post:

 if ( !is_string($text) && is_array($text) ) {
    echo "<pre>";
    print_r($text);
    debug_print_backtrace();
    echo "</pre>";
  }

I'm getting an gigantic array, as soon as I edit the panels page, which looks like a complete textual dump of the Panels page. Since I have no idea how a "backtrace" is supposed to look like, I'm not attaching this data dump. It does not look like the excerpt posted in the original issue.

Letharion’s picture

Status: Active » Closed (won't fix)

This issue is unfortunately extremely general, and can be caused by a wide variety of problems.
Each instance of errors of this general type needs to be backtraced. What asb has done in #5 is correct.
When a complete backtrace is printed, the variables are printed as well, which can get quite big.
I recommend using webchick's trick for debugging: http://www.lullabot.com/articles/quick-and-dirty-debugging

I'm going to close this issue as there are likely several different causes for the same message. If you have this error, then please open a separate issue, with a complete backtrace attached, or search the queue for such an issue posted. :)