title: Get PHP class namespace dynamically
body: <p>How can I retrieve a class namespace automatically?</p>
  
  <p>The magic var <code>__NAMESPACE__</code> is unreliable since in subclasses it's not correctly defined.</p>
  
  <p>Example:</p>
  
  <p><code>class Foo\bar\A</code> -> <code>__NAMESPACE__</code> === Foo\bar</p>
  
  <p><code>class Ping\pong\B extends Foo\bar\A</code> -> <code>__NAMESPACE__</code> === Foo\bar (it should be Ping\pong)</p>
  
  <p>ps: I noticed the same wrong behavior using <code>__CLASS__</code>, but I solved using <code>get_called_class()</code>... is there something like <code>get_called_class_namespace()</code>? How can I implement such function?</p>
  
  <p>UPDATE:<br>
  I think the solution is in my own question, since I realized <code>get_called_class()</code> returns the fully qualified class name and thus I can extract the namespace from it :D
  ...Anyway if there is a more effective approach let me know ;)</p>