Illegal string offset '#children' in drupal_render()
Asked Answered
L

7

5

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?

Leaseback answered 30/5, 2013 at 11:58 Comment(5)
Do you use the latest Drupal core version? Have pretty the same issues with php 5.3/5.4 compatibility, and upgrading to the latest Drupal 7.22 did the trick.Abbacy
But does the calendar display properly?Burger
@RDX yes, the calendar show just fine at the bottom...Leaseback
@Abbacy I'm running this version, still nog success ;-(Leaseback
@Leaseback posted a solution below, can u pls check if that works?Burger
B
3

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

Burger answered 9/6, 2013 at 7:52 Comment(6)
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///Leaseback
hi, yes its working now. i was trying this in th php.ini. thank youLeaseback
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...Leaseback
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.Burger
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.Fermi
I agree with @Fermi — 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!Flopeared
R
17

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

Ronald answered 2/3, 2014 at 20:6 Comment(0)
S
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

Schnur answered 2/6, 2013 at 13:43 Comment(1)
Thank you david for this information on debugging etc, i'll try this outLeaseback
B
3

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

Burger answered 9/6, 2013 at 7:52 Comment(6)
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///Leaseback
hi, yes its working now. i was trying this in th php.ini. thank youLeaseback
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...Leaseback
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.Burger
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.Fermi
I agree with @Fermi — 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!Flopeared
N
1

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]);
+      }
     }
   }
Nottage answered 9/5, 2019 at 10:27 Comment(0)
M
0

I was getting tons of similar warnings with Drupal 7.23 and PHP 5.4, especially from Panels. I just changed the PHP version from 5.4 to 5.3 (single php.ini) in the cPanel/PHP Config and all these warnings and notes disappeared.

Mortification answered 2/10, 2013 at 0:17 Comment(0)
T
0

Whether it helps I don't know, but I had a similar error message, it was due to me changing the machine name of a content type.... I reverted to the previous backup, which had the content type altered as well, deleted it, recreated it with the intended name and all is good

Tutelary answered 9/3, 2015 at 12:12 Comment(0)
I
0

Related issue: in module commons_events, equivalent error messages were triggered by a migration from PHP 5.3 to 5.4 and fixed in #1995834: PHP 5.4 Attend an Event page errors to screen in comment #13.

Idalia answered 21/2, 2018 at 7:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.