title: Calling a PHP function defined in another namespace without the prefix
body: <p>When you define a function in a namespace,</p>
  
  <pre><code>namespace foo {
      function bar() { echo "foo!\n"; }
      class MyClass { }
  }
  </code></pre>
  
  <p>you must specify the namespace when calling it from another (or global) namespace:</p>
  
  <pre><code>bar();          // call to undefined function \bar()
  foo\bar();      // ok
  </code></pre>
  
  <p>With classes you can employ the "use" statement to effectively import a class into the current namespace [Edit: I thought you could "use foo" to get the classes, but apparently not.]</p>
  
  <pre><code>use foo\MyClass as MyClass;
  new MyClass();  // ok, instantiates foo\MyClass
  </code></pre>
  
  <p>but this doesn't work with functions [and would be unwieldy given how many there are]:</p>
  
  <pre><code>use foo\bar as bar;
  bar();          // call to undefined function \bar()
  </code></pre>
  
  <p>You can alias the namespace to make the prefix shorter to type,</p>
  
  <pre><code>use foo as f;   // more useful if "foo" were much longer or nested
  f\bar();        // ok
  </code></pre>
  
  <p>but is there any way to remove the prefix entirely?</p>
  
  <p>Background: I'm working on the Hamcrest matching library which defines a lot of factory functions, and many of them are designed to be nested. Having the namespace prefix really kills the readability of the expressions. Compare</p>
  
  <pre><code>assertThat($names, 
      is(anArray(
          equalTo('Alice'), 
          startsWith('Bob'), 
          anything(), 
          hasLength(atLeast(12))
      )));
  </code></pre>
  
  <p>to</p>
  
  <pre><code>use Hamcrest as h;
  h\assertThat($names, 
      h\is(h\anArray(
          h\equalTo('Alice'), 
          h\startsWith('Bob'), 
          h\anything(), 
          h\hasLength(h\atLeast(12))
      )));
  </code></pre>