[development] $node namespace woes -- can we fix this in D6?

Derek Wright drupal at dwwright.net
Wed May 30 01:02:08 UTC 2007


hello world,

i've had a series of bugs in the project* issue queues[1] caused by  
the fact that the project* modules use $node->pid just like "pid"  
always means in the project* codebase: the project id, or the nid of  
the project node that the (release|issue|...) belongs to.

however, book.module thinks $node->pid is the nid of the parent page  
in the book hierarchy. :(  so, all hell breaks loose when you try to  
put a release node into a book outline.

certainly other contribs might use $node->pid to mean all sorts of  
things, too, which would conflict with both project* and book.module.

i could always just hack project* to always prefix everything it  
tries to stuff into or read from $node with some kind of custom  
variable name prefix, like calling this "$node->project_issue_pid"  
instead of just "$node->pid".

however, given that the API isn't quite frozen for D6 yet, i'm  
wondering if there's anything smarter and better we could do via the  
core API, instead of relying on convention and luck to avoid this  
problem...

1) what's the right way to handle variable namespaces in the $node  
object?  can/should we change hook_nodeapi('load') to force people to  
use a namespace of some kind when populating $node?  maybe $node  
should be a nested array instead of an object, so that everyone touches:

$node[$module_name][$variable_name]

instead of just:

$node->variable_name

??  that probably sucks for all sorts of reasons, i'm just quickly  
brainstorming here...


2) presumably this has come up before?  anyone have pointers to  
relevant old issues or threads?  i don't remember seeing anything  
like this come up before, but i've been known to miss the occasional  
thread on this list. ;)


3) anyone else interested in making a little push to try to do this  
for D6?


4) would the D6 core maintainers be willing to commit a patch if it  
materialized and was properly reviewed/tested/RTBC'ed?


thanks,
-derek (dww)


[1] for the interested reader:
http://drupal.org/node/98278
http://drupal.org/node/124846
http://drupal.org/node/145782




More information about the development mailing list