Hi,
Modules in Drupal 6 should now use menu_get_object() to retrieve a loaded object based on the path. This only applies to certain types (e.g. node, user, menu, etc). The full list of types can be found at menu_get_object(). See http://drupal.org/node/114774#menu_get_object for more information.
The attached patch allows coder to check for lines like:
if (arg(0) == 'node' && is_numeric(arg(1) && ($node = node_load(arg(1))) {
and gives a warning suggesting using menu_get_object() instead. However, it doesn't currently warn about lines like:
if (arg(0) == 'node') {
as I was afraid it might give some false positives, i.e. in situations where the module is checking the path but doesn't actually attempt to load the object. This means we could miss some situations where the object is loaded on a subsequent line. We just need to choose which side we wish to err on.
Cheers,
Stella
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | coder_223908.patch | 1.94 KB | stella |
| coder_menu_get_object.patch | 2.13 KB | stella |
Comments
Comment #1
stella commentedComment #2
douggreen commentedWhy node just check for
(user|node)_load\(arg\([0-9]\)\)?Comment #3
stella commentedYes I don't see why that wouldn't work. I've recreated the patch, see attached.
Cheers,
Stella
Comment #4
douggreen commentedThat looks cleaner.
Often when I do this, I put
arg(0)in a variable such as$argor$arg0. Do you think this is common practice, and should we also check for variable names that begin with $arg?Comment #5
stella commentedWe probably could check on $arg too, though there may be a couple of false positives. I don't know how widespread such $arg usage is, but I don't think you're the only one :)
Stella
Comment #6
douggreen commentedlet's avoid false positives
Comment #8
stella commentedOk, shall I check in the latest patch then?
Comment #9
douggreen commentedI haven't tested it, but if it works for you, then yes please check it in.
Comment #10
stella commentedChecked in.
Cheers,
Stella
Comment #11
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.