By webel on
Since I upgraded to Drupal6.15 (along with about a dozen recommended modules updates) I get the following well known (dare I say infamous) side-effect warning:
warning: preg_match() expects parameter 2 to be string, array given in [...]/includes/bootstrap.inc on line 791.
I've inserted the following dump and backtrace into bootstrap.inc:
function drupal_validate_utf8($text) {
if (strlen($text) == 0) {
return TRUE;
}
///2010-01-30 DEBUG
try {
if (is_array($text)) {
var_dump($text); //DEBUG;
ddebug_backtrace();// needs Devel module on
throw new Exception("array passed as text to drupal_validate_utf8");
}
} catch (Exception $e) {
echo "Caught Exception('{$e>getMessage()}')\n<pre>{$e}</pre>\n";
}
///
return (preg_match('/^./us', $text) == 1);
}
I get the following:
array(2) { [0]=> string(7) "8 reads" [1]=> string(7) "0 reads" } Caught Exception ('array passed as text to drupal_validate_utf8')
exception 'Exception' with message 'array passed as text to drupal_validate_utf8' in [...]/includes/bootstrap.inc:785
Stack trace:
#0 [...]/includes/bootstrap.inc(741): drupal_validate_utf8(Array)
#1 [...]/includes/theme.inc(1177): check_plain()
#2 [...]/includes/theme.inc(617): theme_links(Array)
#3 [...]/includes/theme.inc(1929): theme()
#4 [...]/includes/theme.inc(658): template_preprocess_node(Array, Array)
#5 [...]/modules/node/node.module(1023): theme()
#6 [...]/modules/node/node.module(1096): node_view()
#7 [...]/modules/node/node.module(1785): node_show()
#8 [...]/includes/menu.inc(348): node_page_view('theme_links', Array)
#9 [...]/index.php(18): menu_execute_active_handler()
#10 {main}
I'm none the wiser. What else can I do to find out what is causing the error ?
Comments
Diagnosing through disable/enable recently upgraded modules
When I upgraded to Drupal6.15, I took the opportunity to upgrade many modules, only due to security recommendations.
Using brute force (and it feels mostly irrelevant) disable of upgraded modules I can now exclude:
- Link 6.x-2,8
- FileField 6.x-3.2
- Date 6.x-2.4
- Calendar 6.x-2.2
..this is ridiculous, there has to be an easier way to find the culprit.
Webel IT Australia, "Elements of the Web", Scientific IT Consultancy,
For PHP-driven Drupal CMS web sites, Enterprise Java, graphical UML, UML Parsing Analysis, SysML, XML.
statistics_counter has array title, check_plain called with arra
Diagnosing the backtrace.
Within
argsof theme_links havestatistics_counter(Array, 1 element), with atitle(Array, 2 elements), with strings "7 reads" and "0 reads".check_plain called with
args(Array, 1 element) which is the (Array, 2 elements), with strings "7 reads" and "0 reads" (fromstatistics_counter).drupal_validate_utf8 then called with
args(Array, 1 element) which is the (Array, 2 elements), with strings "7 reads" and "0 reads" (fromstatistics_counter).However, drupal_validate_utf8 expects a string arg, not an array.
Surely this is not a core Drupal 6.15 problem ?
Can somebody please explain to me how to find the cause of this problem, this has now wasted hours of my time, and just because I performed recommended security upgrades, which should not have such side-effects.
Webel IT Australia, "Elements of the Web", Scientific IT Consultancy,
For PHP-driven Drupal CMS web sites, Enterprise Java, graphical UML, UML Parsing Analysis, SysML, XML.
The call_user_func_array
The call_user_func_array takes place in menu.inc
line (Integer) 348:
And although (and I confess proudly that I'm UML-driven Java boy and Netbeans IDE fan) I love the ability to manipulate functions as strings sometimes, the way function as strings are thrown around in PHP-based Drupal makes it infuriatingly difficult to diagnose anything. Could somebody please help me isolate the cause of this most annoying and common of errors (and surely not one I caused). I am a real coder, and I don't mind getting my hands dirty, even in PHP, however this is so much harder than it need be, because Drupal does not leverage obvious object-oriented strategies, preferring it seems at every turn function-manipulation tricks (and they are mostly not necessary, and makes thinks darn hard to trace).
How do I find which module, or which part of core, is causing drupal_validate_utf8 to be called incorrectly with
statistics_counteras an array ?And who would not be tempted to just hack core to silence drupal_validate_utf8 whenever it is invoked with an array ? I could die figuring it out.
Webel IT Australia, "Elements of the Web", Scientific IT Consultancy,
For PHP-driven Drupal CMS web sites, Enterprise Java, graphical UML, UML Parsing Analysis, SysML, XML.
The cause is the core (optional) statistics module
Brute force Google search brought me to: http://api.drupal.org/api/function/statistics_link/6
Buried (because it is a string key PHP-like, not a real var) inside the statistics.module, I find:
(From that point on of course, all diagnostics become more difficult, because one has to go hunting for the string 'statistics_counter' as $links is passed around.)
Switching off the Statistics 6.15 gets rid of the message from drupal_validate_utf8.
So it IS a core (optional) Drupal 6.15 problem, and because I upgraded to it on the basis of a security warning I had hours of my time wasted (not least because the way Drupal is coded is so unnecessarily hard to trace), and I would rather have used the time for something useful.
Webel IT Australia, "Elements of the Web", Scientific IT Consultancy,
For PHP-driven Drupal CMS web sites, Enterprise Java, graphical UML, UML Parsing Analysis, SysML, XML.
Reported as bug in statistics.module 6.15 core (optional)
#701996: statistics_counter with array title incorrectly passed (eventually) to drupal_validate_utf8($text) in bootstrap.inc 777
Includes backtrace as image (krumo style), revealing array with key
statistics_counterburied inside$links.Webel IT Australia, "Elements of the Web", Scientific IT Consultancy,
For PHP-driven Drupal CMS web sites, Enterprise Java, graphical UML, UML Parsing Analysis, SysML, XML.