E_NOTICE thrown by element_children() on user/%uid/edit page
tic2000 - July 12, 2009 - 17:57
| Project: | Drupal |
| Version: | 7.x-dev |
| Component: | base system |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
When I go to user edit page I see
* Notice: Uninitialized string offset: 0 in element_children() (line 4045 of /home/tic2000/public_html/d7/includes/common.inc).
* Notice: Uninitialized string offset: 0 in element_children() (line 4045 of /home/tic2000/public_html/d7/includes/common.inc).
The patch solves the problem.
| Attachment | Size | Status | Test result | Operations |
|---|---|---|---|---|
| user-edit-remove-notice.patch | 771 bytes | Idle | Failed: 11168 passes, 663 fails, 585 exceptions | View details |

#1
More precisely, this patch *hides* the problem. Please find why element_children() is bumping into a string where it should find an array. That's probably due to something like this:
<?php$form['title'] = "toto";
?>
instead of
<?php$form['#title'] = "toto";
?>
#2
No. In that case $key[0] would be 't' and no notice would be thrown.
#3
The problem comes from this
// For the default theme, revert to an empty string so the user's theme updates when the site theme is changed.$info->key = $info->name == variable_get('theme_default', 'garland') ? '' : $info->name;
in system_theme_select_form().
And now that I look at that code I see an usability problem too. A user can't select a default theme to be his default theme. If the site's default theme changes his theme changes too, even if he actually selected a certain theme (which happen to be the default theme of the site at that time).
Now, do we solve the initial problem? I know drupal doesn't babysits broken code, but I don't know if using an array with an empty key qualifies as broken code.
For the usability problem, I think that theme selection form on user edit page should have an option "Use default theme" which should use 'use_default_theme' as $key to avoid the Notice message.
#4
The empty string is not really a valid key. If you do want to hide that under the carpet, you would at least need to use
strlen($key) > 0.I believe we still need to fix the root issue.
#5
#6
This patch treats the root of problem instead of just making it shut up.
#7
The last submitted patch failed testing.
#8
Lets see if this one passes.
#9
I'm not sure I understand this one right, why does an empty string key in a
#options(which is perfectly valid) causes notices in element_children()? This sounds weird.#10
Because element_child() does an foreach $key => $value and inside that does a $key[0] which should get the first character of the string, but if there is no string in throws a Notice.
Why is element_child() called on that is above my expertise right now.
Edit: I opened #517662: Can't select site's default theme as user's theme for the usability problem.
#11
Fix to the title :)
#12
The last submitted patch failed testing.
#13
core was broken
#14
per-user configurable themes removed from core.
renders this issue moot.
see #292253: Remove the per-user themes selection from core and http://drupal.org/node/517662#comment-1900532
#15