Closed (won't fix)
Project:
Drupal core
Version:
5.0-rc1
Component:
forms system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
26 Dec 2006 at 20:46 UTC
Updated:
31 Jul 2014 at 11:09 UTC
Jump to comment: Most recent
Comments
Comment #1
ChrisKennedy commentedPlease describe the action that is giving this error.
Comment #2
peterx commentedI was changing menus in a module. Switching to Drupal 5.0 and adding more menu entries. I occasionally received the error message and not always on the same line. When I added diagnostics to forms.inc, I found I was passing $form as a string instead of an array. On one occasion it was because I passed $form through a theme function. On other occasions the error was so obscure that I reverted code to an earlier version and started again, wasting a lot of time.
The error would be obvious in PHP 4 but is not obvious in PHP 5. In PHP 4, the error would occur on almost the first line of drupal_prepare_form() and the message would tell you that $form is a string instead of an array. In PHP 5 the error occurs after some successful processing of $form as a string instead of an array.
I do not call drupal_prepare_form() anywhere in my code which results in a long process to find which part of my code calls something that calls drupal_prepare_form(). Just the act of documenting this error will help other people fix their problems instead of blaming drupal_prepare_form(). Will the regular drupal.org site search find this entry? Should I post something that points to this error so that it appears in the search?
Comment #3
peterx commentedI tested the site search and it finds this entry. That means other people with the same error can find this report and work out what is happening.
It is PHP 5 treating a string as an array instead of reporting the real error. You have a string going into a form function where you should have an array.
Comment #4
ebob-1 commentedI reproduced the error with this:
The crucial mistake I made was setting $items instead of $items[].
Comment #5
heine commentedGIGO principle.
Comment #6
rod.murphy commentedI 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.
Comment #7
mpruitt commentedI had the same error. Turned out it was the way I was calling the function:
Original Code:
Edited Code:
Comment #8
OptimusPrime23 commentedThis happens when you have a function declaration with an argument and a value is assigned to the same inside the function.
for example:
Comment #9
houmem commentedthat appear when the code in the $schema variable is false, for me at least