Doc #74257 [Fbk->Opn]: "namespace \X" does not work to declare a namespace
Edit report at https://bugs.php.net/bug.php?id=74257&edit=1
ID: 74257
Updated by: requinix@php.net
Reported by: david at grudl dot com
Summary: "namespace \X" does not work to declare a namespace
-Status: Feedback
+Status: Open
Type: Documentation Problem
Package: Scripting Engine problem
PHP Version: 7.1.2
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
@roy-orbison is saying that
> namespace \Identifier;
should either work as a namespace definition or be a parse error. Because of the space. The former
is not possible because it's ambiguous with the namespace\ root, and the latter is not great
because it assigns significance to the whitespace that did not exist before.
So I figure we address the problem by adding a quick note to
https://www.php.net/manual/en/language.namespaces.definition.php
docs that says not to use a leading slash when defining a namespace. (Of course, anyone who did so
would very quickly realize it didn't work.)
Previous Comments:
------------------------------------------------------------------------
[2020-03-13 16:40:19] cmb@php.net
What is supposed to be missing from the documentation?
------------------------------------------------------------------------
[2019-01-31 22:51:34] roy-orbison at devo dot net dot au
Indeed, but that error is not picked up by linting, and the message is for an undefined constant.
------------------------------------------------------------------------
[2019-01-31 01:30:42] requinix@php.net
Keep in mind OP had to define X as a constant. In the real world namespaces have more meaningful
names and it's unlikely there will be a constant by the same name, so code would create an
error.
Additionally, "namespace\" is documented in "namespace keyword and __NAMESPACE__
constant"
http://php.net/manual/en/language.namespaces.nsconstants.php
------------------------------------------------------------------------
[2019-01-31 01:16:25] roy-orbison at devo dot net dot au
This is definitely a bug. If PHP devs really think it's a feature, why isn't it documented
in "Defining Namespaces"? There is no way anyone would expect the following to be anything
other than a definition.
namespace \Foo\Bar;
Accessing members of a namespace relative to global is done with a leading backslash, so why not the
same for defining? It should at least be a syntax error rather than evaluate and cause a fatal error
or silently fail. That type of expression could only read a constant without doing any assignment,
thus have no effect on other userspace state, right? So what's the point of allowing it without
even a warning?
------------------------------------------------------------------------
[2017-03-16 16:46:49] tpunt@php.net
^ See above comment...
------------------------------------------------------------------------
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
https://bugs.php.net/bug.php?id=74257
--
Edit this bug report at https://bugs.php.net/bug.php?id=74257&edit=1
Thread (5 messages)