[development] Drupal - to use objects or arrays
adrian at bryght.com
Wed Jan 10 11:13:28 UTC 2007
On 10 Jan 2007, at 10:58 AM, AjK wrote:
> If only that were true. I'll give you an example of where it isn't
> true. I once created a "directory of people" for a client. I
> created a node type to hold the records so tax could be used. I
> created a form builder function and a db update function to handle
> it. All's well. Then the client says "some of the people in the
> directory are actual site users, would be nice if those users could
> be joined to their record so they can edit their own entry". Made
> sense, so I used a tab in "my account" to allow for "per user"
> editing and I initially tried to reuse my existing form builder and
> db update functions. Guess what? When the form is submitted on
> "edit node" the update function gets an object, when it's submitted
> via drupal_get_form() it's an array. Solution, I just cast the
> array to object in the db update function. But it demonstrates
> where Drupal is not consistent in it's use of data type containers.
> Is it an array or an object? Who knows unless you test for it.
Well. Forms in html / php are returned as arrays. And any casting we
do from that, is going to end up having to be cast back if
we want to use the form submission stuff.
Some of my data api stuff requires doing away with objects in
relation to forms / data models entirely (such as fixing the horrible
node form situation where you have to
pass it an empty node object with the right type)
Arrays are just simpler and more flexible to work with in php. We
often need to do things like array_merge, which won't work with objects.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the development