|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-07-24 11:26 UTC] simon at stienen dot name
Description:
------------
So much wrong here ...
The initial intention was to get back into global namespace using the "namespace X;" syntax. (Why isn't this possible? Neither as namespace; namespace \; ... not even namespace \\;)
Curiously, "namespace \" expected the name of a constant.
Even more curiously, "namespace \foo" is looking for the constant "foo" in the *current* namespace.
If the constant exists, the namespace directive is simply ignored.
If it does not, the script dies with a fatal error.
Reproduce code:
---------------
namespace Foo;
const Bar = "Blob";
namespace \Bar;
function x() { echo __NAMESPACE__; }
x();
Expected result:
----------------
Pretty much everything else than the actual result ... but at least "Bar" or "Blob"
Actual result:
--------------
Foo
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 21 03:00:01 2025 UTC |
Whyever this is necessary: <?php namespace Foo; const Bar = "Blob"; namespace \Bar; function x() { echo __NAMESPACE__; } x(); ?> ... happy now?)more to the point, here are 2 scripts that do what you want it to do: <?php namespace Foo; const Bar = "Blob"; namespace Bar; function x() { echo __NAMESPACE__; } x(); // echoes "Bar" ?> <?php namespace Foo { const Bar = "Blob"; } namespace Bar { function x() { echo __NAMESPACE__; } x(); // echoes "Bar" } ?> and to go to global namespace, there is only one way: <?php namespace Foo { const Bar = "Blob"; } namespace { function x() { echo __NAMESPACE__; } x(); // echoes nothing } ?>