Doc #74257 [Asn->Csd]: "namespace \X" does not work to declare a namespace

From: Date: Fri, 13 Mar 2020 17:38:00 +0000
Subject: Doc #74257 [Asn->Csd]: "namespace \X" does not work to declare a namespace
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-17413@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74257&edit=1

 ID:                 74257
 Updated by:         cmb@php.net
 Reported by:        david at grudl dot com
 Summary:            "namespace \X" does not work to declare a namespace
-Status:             Assigned
+Status:             Closed
 Type:               Documentation Problem
 Package:            Scripting Engine problem
 PHP Version:        7.1.2
 Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

Thanks @requinix!


Previous Comments:
------------------------------------------------------------------------
[2020-03-13 17:37:35] cmb@php.net

Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=349407
Log: Fix #74257: "namespace \X" does not work to declare a namespace

------------------------------------------------------------------------
[2020-03-13 16:50:24] requinix@php.net

@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.)

------------------------------------------------------------------------
[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

------------------------------------------------------------------------


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)

« previous php.doc.bugs (#17413) next »