Without the burden of loading the heavy $node objectAnother option, in D7:
function _my_module_get_nid() {
$path_args = explode('/', current_path());
//$nid = $path_args[1];
if(is_int($path_args)) {
return($path_args[1]);
}
// Log that we failed to load a NID.
else {
watchdog('my_module', 'Unable to gather NID at: ' . current_path(), WATCHDOG_WARNING, NULL);
return FALSE;
}
}
If you plan to use the function outside your module, do not use the leading _ at the begining of the name of the function.