It first appeared when I updated to the newest CCK, Facebook Style Statuses, Cumulus, and OG for Drupal 6.6. I have removed each and everyone of these modules completely and it has not gone away. I have run update.php a few times. Optimized the database. Cleared the cache. Did some cron runs. Looked up the issues here at Drupal.org followed some of the advice hear except I did not want to run a patch listed here which I do not know will cause problems in the future . I do not know much php so I was wondering if anyone knew anything else I could do to tackle this problem . Any help is appreciated.

I have the most up to date php. I have an apache server. Its drupal version 6.6. All drupal paths are affected. It happens when I use any kind of web browser.

CommentFileSizeAuthor
#2 drupal-n332345.patch856 bytesdamienmckenna

Comments

DaveIsFluffy’s picture

This normally stings me when I double up on a form element. How it got me: I was working on a module that displayed user profiles, so I started off with the profile.module and got hacking (this was not only my first Drupal code ever, also my first PHP).
To cut a long story short, when accessing pages that had common elements between my module and profile.module, there were two elements that had the same name and so PHP had avoided throwing an error by making the two strings into an array.

To do some troubleshooting on this, start disabling modules till it starts working again. The direct path (to side step any errors like you've seen) is /admin/build/modules

damienmckenna’s picture

Version: 6.6 » 6.14
Status: Active » Needs review
StatusFileSize
new856 bytes

Here's a patch that modifies drupal_attributes() to support attribute values that are arrays.

boftx’s picture

Status: Needs review » Needs work

I just got hit with what is essentially the same error with the project bundle:

warning: preg_match() expects parameter 2 to be string, array given in htdocs/includes/bootstrap.inc on line 777.

From looking at many other reports for this and similar errors, and looking at the code, it seems to me that the culprit is the check_plain function itself.

function check_plain($text) {
  return drupal_validate_utf8($text) ? htmlspecialchars($text, ENT_QUOTES) : '';
}

That function is called for many different reasons. This error is going to be produced whenever it is called to check a display field that potentially has an array value such as is provided by a pulldown select field.

I believe the correct fix for this, which will fix many different contrib modules at thesame time, is to have check_plain detect an array and then call drupal_validate_utf8 on each member of the array, replaceing as needed. Here is the logic I am proposing:

function check_plain($text) {
  if ( $text a string )
    // keep original functionality
    return drupal_validate_utf8($text) ? htmlspecialchars($text, ENT_QUOTES) : '';
  else if ( $text is reall an array ) {
    foreach $member in $text {
      $member = drupal_validate_utf8($text) ? htmlspecialchars($text, ENT_QUOTES) : '';
      replace original value in $text array with $member;
    }
  }
}

I am not a PHP person, I work mainly in perl and c, or I would do this myself.

Again, a search for "warning: preg_match() expects parameter 2 to be string" indicates that this is a very common problem and the intermitent nature is driving people nuts.

damienmckenna’s picture

boftx: I think it's perfectly acceptable for a string function to only handle strings, it's the responsibility of other code to ensure that only strings are passed to it - most languages work this way, a does PHP itself.

boftx’s picture

I agree with your statement in principle, and in my own shop would enforce that ruthlessly.

But given how widespread this is, and the apparent ability for code to call check_plain with an array unbeknownst to the programmer, I think some defensive action is called for. Most of the reports I have read stem from using a view or CCK fields. This implies that an end-user could conceivably create an error of this type simply by changing an existing field.

Because of this I submit for consideration that this function, check_plain, needs to be re-implemented to handle arrays as well as strings. A review of some of the modules having this problem will probably indicate what the expected return needs to be when called with an array. It might well be that simply modifying the values in-place will be sufficient.

If nothing else, an error message with a reasonable back trace should be produced.

Thank you for responding.

drupdruppalpal’s picture

hi,
same here,

what do you think about that solution?
http://drupal.org/node/525036

i dont like but i need to solve it.
regards

webel’s picture

following, after many hours trying to get behind this problem after upgrading to Drupal6.15 and many recommended module upgrades:

How diagnose: warning: preg_match() expects parameter 2 to be string, array given in .../includes/bootstrap.inc 777

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.