Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Illegal string offset '#children' in drupal_render()

My full calendar throws errors when seen from the site:

Warning: Invalid argument supplied for foreach() in element_children() (regel 6400 van C:\Users\Simon\My Websites\Xampp\htdocs\xxx\includes\common.inc).
Warning: Illegal string offset '#children' in drupal_render() (regel 5867 van C:\Users\Simon\My Websites\Xampp\htdocs\xxx\includes\common.inc).
Warning: Illegal string offset '#children' in drupal_render() (regel 5877 van C:\Users\Simon\My Websites\Xampp\htdocs\xxx\includes\common.inc).
Warning: Illegal string offset '#children' in drupal_render() (regel 5915 van C:\Users\Simon\My Websites\Xampp\htdocs\xxx\includes\common.inc).
Warning: Illegal string offset '#printed' in drupal_render() (regel 5922 van C:\Users\Simon\My Websites\Xampp\htdocs\xxx\includes\common.inc).

I have read somewhere that it doesn't work well under PHP 5.4xx.

Anyone a solution?

like image 966
Nomistake Avatar asked May 30 '13 11:05

Nomistake


4 Answers

Better advice is as follows:

1) To hide warnings/errors/notices from users on a live Drupal 7 site, go to [SITE]/admin/config/development/logging and turn off the display of errors. Don't do it in your settings file, as you then lose the ability to find problems.

2) It is often worthwhile to do a bit of debugging. While it is true that, as a general matter, warnings and notices can be safely ignored, they will slow down your site ( see Does php run faster without warnings? ). Often the error is the result of a known problem with a particular Drupal module, and there may be a patch posted on drupal.org that fixes the problem. The source of this particular (and common) bug can be difficult to track down, but there's a helpful discussion for how to do it here: http://fuseinteractive.ca/blog/put-your-children-their-place-drupal-debug-snippet

In your case, it's probably a bug in the Calendar module (assuming that's what you're using to produce your calendar), and you probably want to look at the issue queue there: https://drupal.org/project/issues/calendar?categories=1

like image 56
Giles B Avatar answered Nov 24 '22 11:11

Giles B


This is a known issue with PHP/Drupal. All the errors that you see are not errors, they're just warnings and can be very safely ignored. You only need to be concerned with lines that start with Error: .....

To safely ignore these warnings, edit your drupal sites/default/settings.php and add the following line:

error_reporting(E_ALL & ~(E_STRICT|E_NOTICE|E_WARNING));

This will also resolve the same issue for potentially other plugins too.

The recommended production setting for Drupal is to disable error reporting altogether, so that your users don't get any cryptic error messages. For a production Drupal site, you must do:

error_reporting(0);

And if you need to see errors in your website, use the nginx logs instead.

Edit: Fix error_reporting, add production notes

like image 23
Subhas Avatar answered Nov 24 '22 11:11

Subhas


It looks like you are trying to render elements that does not have the proper array layout. Try to use debug_backtrace() and debug_print_backtrace() to find the code that is causing the warnings.

Also you can also uninstall modules and see when the error does away. Be sure to clear your cache to be sure you are not fooled by anything.

Other commands you can use is dd() dpm() krumo() from the devel-module.

Also look at: http://php.net/display-errors and http://php.net/display-startup-errors

David

like image 41
roheim Avatar answered Nov 24 '22 11:11

roheim


Adding this patch to the common.inc helped me fix my problems

diff --git a/includes/common.inc b/includes/common.inc
index c6303ef..e8f7e66 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -6007,7 +6007,9 @@ function drupal_render(&$elements) {
 // for speed.
 if ($elements['#children'] == '') {
 foreach ($children as $key) {
-      $elements['#children'] .= drupal_render($elements[$key]); 
+      if (is_array($elements[$key])) {
+        $elements['#children'] .= drupal_render($elements[$key]);
+      }
     }
   }
like image 28
Sanjok Gurung Avatar answered Nov 24 '22 11:11

Sanjok Gurung