#49046 [Bgs]: namespaces with leading \ misbehave

From: Date: Fri, 24 Jul 2009 16:58:41 +0000
Subject: #49046 [Bgs]: namespaces with leading \ misbehave
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-140217@lists.php.net to get a copy of this message
ID: 49046 Updated by: cellog@php.net Reported By: simon at stienen dot name Status: Bogus Bug Type: Scripting Engine problem Operating System: FreeBSD PHP Version: 5.3SVN-2009-07-24 (SVN) New Comment: 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 } ?> Previous Comments: ------------------------------------------------------------------------ [2009-07-24 16:47:42] cellog@php.net note that there is some dissent amongst developers about the usefulness of the "namespace" operator, so this may go bye-bye in a future PHP 5.3.x, in which case this bug will re-open ------------------------------------------------------------------------ [2009-07-24 16:46:10] cellog@php.net the code below is looking for the Bar constant in the current namespace, see http://us3.php.net/manual/en/language.namespaces.nsconstants.php ------------------------------------------------------------------------ [2009-07-24 16:38:28] derick@php.net Nonsense Jani, we allow more than on per file. Dmitry, could you please have a look? ------------------------------------------------------------------------ [2009-07-24 15:32:54] jani@php.net RTFM: http://www.php.net/manual/en/language.namespaces.definition.php You can only have one namespace per file.. ------------------------------------------------------------------------ [2009-07-24 13:18:46] simon at stienen dot name Whyever this is necessary: <?php namespace Foo; const Bar = "Blob"; namespace \Bar; function x() { echo __NAMESPACE__; } x(); ?> ... happy now?) ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/49046 -- Edit this bug report at http://bugs.php.net/?id=49046&edit=1

« previous php.bugs (#140217) next »