# Request for a function or constant to expose which namespace the current code is running under.

- Thread: https://externals.io/message/44555
- Original archive: https://news-web.php.net/php.internals/44555
- Started by Michael Shadle on 2009-06-30T17:45:04+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #44555 — Michael Shadle — 2009-06-30T17:45:04+00:00

URL: https://externals.io/message/44555#44555

Namespaces in PHP are scaring me.

I can only imagine some of my developers creating code and using
namespaces - and how do you identify which namespace a function, class
or chunk of code is under?

It looks like you can define namespaces anywhere.

If I'm looking for a specific function, and it's in two include files,
how do you know which namespace the function is written under? Some
sort of manual backtrace?

Is there a magic constant like __NAMESPACE__ or a function that can
return the name of the namespace the code is currently running under?

At the moment I would actually be telling my developers when I switch
over to 5.3.0 to NOT use namespacing. We don't need it in any of our
applications, and it will just complicate things...

---

## #44556 — Stanislav Malyshev — 2009-06-30T17:56:40+00:00

URL: https://externals.io/message/44555#44556 · In reply to: #44555

Hi!

> If I'm looking for a specific function, and it's in two include files,
> how do you know which namespace the function is written under? Some
> sort of manual backtrace?

Namespaces are local to files.

> Is there a magic constant like __NAMESPACE__ or a function that can
> return the name of the namespace the code is currently running under?

"namespace the code is currently running under" is meaningless, since 
namespace is a compile-time concept. There is __NAMESPACE__ constant 
which is equal to currently compiles namespace.
http://www.php.net/manual/en/language.namespaces.nsconstants.php
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com
