[development] The array argument in hook_user: can we get rid of it?
merlin at logrus.com
Tue Feb 6 19:39:52 UTC 2007
Nedjo Rogers wrote:
> Unlike our other object hooks (e.g., hook_nodeapi, hook_taxonomy),
> hook_user passes two arguments by reference. Both are representations of
> the user object, one in array and the other in object format.
> There's a lot of interest in streamlining our object handling. I've been
> working on a set of generalized object handling methods that build on
> our current ones in http://drupal.org/node/113435.
> As I dig into this, I'm finding that hook_user's difference from our
> other hooks is one of the main barriers. Maintaining this double pass by
> reference would force all other object types to do the same, even though
> they don't have data they need to pass.
> Hence my question: can we change hook_user to behave like the other
> object hooks, passing a single argument (the user object) by reference?
> Looking at the implementations in user.module, this double passing looks
> to be mainly a matter of convenience--separating out what are parameters
> to match (user_load()) or extended user attributes (user_save()) from
> the base user object. My hunch is, if they're user data they're user
> data as far as hook implementations are concerned, so it shouldn't
> matter much if they're passed in a single object. But maybe this is
> wishful thinking.
> I'm thinking a patch to change hook_user to pass a single argument by
> preference may be a necessary prior patch to getting a generalized set
> of methods in. Thoughts?
THe reason hook_user works like that is so that you can edit only part of a
user object, which is currently a necessity for profile module. Changing the
structure may well be a good idea, but will have very widespread ramifications,
and will need a way to retain the current abilities.
More information about the development