By paese on
I got the following error:
Fatal error: Cannot use string offset as an array in /home/httpd/vhosts/bla.org/httpdocs/includes/form.inc on line 679
On path http://www.bla.org/admin/settings/search for administer search settings.
Lines in form.inc
678 if (isset($form['#disabled']) && $form['#disabled']) {
679 $form['#attributes']['disabled'] = 'disabled';
680 }
I really don't get it. What's wrong here?
Paese
Comments
This error happens when you
This error happens when you try to access a variable like an array when
the variable was initialised with a different type than array.
That was clear as the PHP Error discribes the problem.
What I didn't know was that this is not a search module issue.
I didn't find out which module calls the function form_builder()
in form.inc with $form=1 but there is one.
So I first check now if $form is an array an then everything is fine now.
if (!is_array($form)) $form = array();Paese
You are treating a patient
You are treating a patient with a braintumor with aspirin. Excise the tumor, ie pass the right thing to drupal_get_form.
Do you use a custom / contributed module that can lead to this error? If it's a custom error, post your code and we can perhaps see the cause. But please see http://heine.familiedeelstra.com/coding-help-tips
--
The Manual | Troubleshooting FAQ | Tips for posting | How to report a security issue.
You are kind of right. The
You are kind of right. The patient gets the wrong medication. The real error still exists. But it's not wrong when you check variables that you expect in a certain format and cast to whatever you need to avoid errors like this. Type hinting would be useful. available for arrays since PHP 5.1
The strange thing is that I do get this error only when I click on http://www.bla.org/admin/settings/search nowhere else.
How can I find out which module/file called form_builder() with the wrong $form parameter?
I had the same problem and
I had the same problem and it will be a problem in one of your contributed modules though.
The easiest way how to debug it would be to open up a modules/search.module file and do something like print_r($form);exit; on line 233. Now if you visit admin/settings/search you will see what is your output of your form.
Maybe from there you will find out which module is adding wrong data. If not, you will have to go through all hook_search in other modules than core as hook_search is being invoked when you run admin/settings/search
hope it helps
__________________________________ ____ ___ __ _ .. .. .
Give a man a fish, and you'll feed him for a day. Teach a man to fish, and he'll buy a funny hat. Talk to a hungry man about fish, and you're a consultant.
- Scott Adams
http://sotak.co.uk
My personal blog | twitter:@sotak
That fixed it for me
Hi sign,
That worked for me, thanks! I had named one of my functions xxxx_search in a custom module, not realizing there was a hook_search.
Best wishes,
Rob
drupal_get_form() being called twice
In case any one searching for this error message comes across this post.
I also got this php error message, but in my case, it was because I was calling drupal_get_form() twice. The first time, the $form array would be converted to a string, then it was called again with $form as a string rather that an array.
It was called twice, because I called drupal_get_form() in my hook_menu() function and then again in the form function that it drupal_get_form() calls. Simple and careless mistake, but took me a while to track down.
Same problem, not calling drupal_get_form() twice
I get the exact same error writing my own module, also in that line
which is at line 972 in my code (Drupal 6.4)
I'm pretty sure the drupal_get_form() gets called only once. drupal_get_form() calls drupal_process_form() which calls form_builder(), which starts iterating over the element_children. It calls itself for 'storage', 'submitted', 'post'. Inside that last call, $form looks ok (at least a populated array). However, it tries to call itself again for form_build_id, which is a string. Therefore, the fatal error is thrown.
I have a form that couldn't be much simpler
And no validating, submitting or themeing (empty functions and 'return drupal_render($form)' respectively)
Only hook_menu calls the drupal_get_form for this form.
And the weirdest thing is: the form _does_ render, the problem only occurs after pressing 'Add group'.
This problem has been driving me crazy for hours and hours (as I hope you can tell from my debugging info). Does anyone know what it could be?
You use the wrong function arguments
From D5 to D6 the arguments for the method that builds the $form array have changed.
In D6 your function should look like this:
Please note that the first argument is now $form_state and no longer $form. Change $form_state to $form (as in D5) and you will run into the described error in form.inc line 972.
This post has solved my problem...
... as well. Cheers!
don't forget the
don't forget the $form=array() at the start of the form, was my issue,
S:)
Thanks a million
This solved the problem for me, after a few hours of useless tracing.
It happened ONLY on the preview area of Views 6.x-3.dev which was really misleading.
Remembered me about my teachers in my early developer's days : "Always initialize your variables, even if the language doesn't constraint you to."
We should never forget this advice, as proven here.
Thank you, that was it for me
Thank you, that was it for me as well.