Using PHP namespace hybrid for Drupal modules I've been getting into PHP namespaces and had a thought about how to clean things up a bit in my custom modules. I was thinking that for hooks I could use the traditional Drupal method of defining functions in the global namespace with the module name prefix but for all other functions and classes I could define them inside a PHP namespace. So, for my module "donut_win" a file would look like this:

&lt;?php
namespace {

function donut_win_menu()
{
  $items['donut/win/%'] = array(
     'title'           =&gt; 'Hey, there!'
    ,'description'     =&gt; "Eveyone wins when donut wins."
    ,'page callback'   =&gt; 'Donut\\Win\\render_page'
    ,'page arguments'  =&gt; array(1)
    ,'access callback' =&gt; true
    ,'type'            =&gt; MENU_CALLBACK
  );

  return $items;
}

function donut_win_cron()
{
  # magic!
}

} # namespace global

namespace Donut\Win {

function render_page ($bingo)
{
  # so much magic!
}

}


I'm interested in what potential pitfalls would be with this method and any other disadvantages or advantages. Is this a good idea or am I crazy?
It looks like there aren't any technical pitfalls. But, using PHP namespacing is not part of Drupal's coding standards. Clive sums it up nicely in a comment on the question:


  Drupal has it's own coding standards which it's best to follow, and namespacing functions isn't part of that. If you're not bothered about the Drupal conventions, then sure, do whatever works for you...but if you're looking to write a module to contribute back to the community, or want it to be understood easily by other Drupal devs in the future, it's best to stick to standards