How can I retrieve a class namespace automatically?
The magic var __NAMESPACE__
is unreliable since in subclasses it's not correctly defined.
Example:
class FooarA
-> __NAMESPACE__
=== Fooar
class PingpongB extends FooarA
-> __NAMESPACE__
=== Fooar (it should be Pingpong)
ps: I noticed the same wrong behavior using __CLASS__
, but I solved using get_called_class()
... is there something like get_called_class_namespace()
? How can I implement such function?
UPDATE:
I think the solution is in my own question, since I realized get_called_class()
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 ;)