One of the code snippets I use on a frequent basis is one to get the nid of the current node.

<?php
if(arg(0)=='node '&& is_numeric(arg(1))){
  $nid = arg(1);
  return $nid; 
}
else{
  return NULL;
}

I use this a lot because it is a lightweight and simple solution. I know there are other solutions such as

global $node

menu_get_object etc.

However I think that these solutions have their own problems. I just wondered what people's opinions were about making this into a very simple module? My reservations are that it means one more module and the performance hit associated for something that is so simple, however every time I require it I have to either scratch about in my code bin or Google it and it is amazing the problems users seem to have and the variety of methods out there so seems a very good candidate to be standardized in some way. I am also undecided as to whether there should be some kind of switch statement to deal with actions etc.

Comments

Note there is no global

Note there is no global $node.

menu_get_object() already provides a single function approach.

Not quite

Sorry I don't mean exactly global $node but in various contexts you can access $node in the same way you can access the global $user variable, however where most users get stuck is when that is not accessible- one of the reasons I don't routinely try to use it.

menu_get_object as you say is a very useful function but it is not the same as getting the node id- menu_get_object gets the complete object, the reason I prefer the above code is to obtain the nid in a lightweight way and have the flexibility to do what I want with it.

I don't understand what such

I don't understand what such a module would do. Would it just provide a function that returns the node ID of the current page? If so, I think it's too much overhead for not much benefit. In any situation where you need to get the ID of a node, there are always ways of doing it simply, some of them different depending on the situation.

I agree

Yes I totally agree and that is why I made the post - there are a lot of different ways, it is just an area of a lot of confusion and one of those things that can be very confusing when you begin developing in Drupal e.g. you can access the $node in a template page but possibly not in your module- obviously when you have a deeper understanding you can understand why. It may be one of those things that is better served by improving the documentation then the various approaches can be explained.

Yes, unfortunately it's not

Yes, unfortunately it's not always obvious how to do a lot of things in Drupal without quite a bit of searching and reading. Comments and forum posts of other users often tend to be more helpful than the documentation, as well as simply looking at the source code of core or other modules to see how they have tackled the same problem.