Illegal string offset '#children' in drupal_render()

15,294

Solution 1

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

Solution 2

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

Solution 3

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

Solution 4

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]);
+      }
     }
   }
Share:
15,294
Nomistake
Author by

Nomistake

Updated on July 25, 2022

Comments

  • Nomistake
    Nomistake over 1 year

    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?

  • Nomistake
    Nomistake almost 11 years
    Thank you david for this information on debugging etc, i'll try this out
  • Nomistake
    Nomistake almost 11 years
    hi, if i use the error reporting settings as above, i get error in syntax. i hav this now: error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED & ~E_WARNING But i'm still getting the errors///
  • Nomistake
    Nomistake almost 11 years
    hi, yes its working now. i was trying this in th php.ini. thank you
  • Nomistake
    Nomistake almost 11 years
    just to be sure, are you sure its save to do it this way? i dont ant to have problems when putting the site online...
  • Subhas
    Subhas almost 11 years
    Yes, they are safely ignorable warnings, none are errors. I get a whole lot of these when running Drupal in development sites, but anything except an actual error (logs starting with ERROR instead of WARNING) is not really a problem.
  • moopet
    moopet almost 8 years
    Wow. Do not do this - do not disable warnings because you don't like seeing them, fix them. If you're seeing illegal offsets and invalid arguments, your code is wrong. By "your" code I include whatever modules you're using. Hiding warnings is never a solution. Send them to a log instead and then deal with them. They're a sign something is wrong, and if you haven't noticed anything breaking, it's just down to luck.
  • featherbelly
    featherbelly over 6 years
    I agree with @moopet — this is really bad advice. Warnings/notices may not BREAK your code but that does not mean you should just ignore them... You'll end up writing sloppy bad code and your logs will be full of these annoying warnings and notices. FIX THEM!