#49982 [Ana->Bgs]: Inclusion of token/syntax keyword in namespace causes Parse error
| From: | vrana@php.net | Date: | Fri, 13 Nov 2009 19:42:29 +0000 |
| Subject: | #49982 [Ana->Bgs]: Inclusion of token/syntax keyword in namespace causes Parse error | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-3116@lists.php.net to get a copy of this message | ||
ID: 49982
Updated by: vrana@php.net
Reported By: swquinn at gmail dot com
-Status: Analyzed
+Status: Bogus
Bug Type: Documentation problem
Operating System: Windows XP Professional
PHP Version: 5.3.0
New Comment:
Already documented at http://www.php.net/manual/en/reserved.php:
"None
of the identifiers listed here should be used as identifiers in any of
your scripts."
Previous Comments:
------------------------------------------------------------------------
[2009-10-31 14:15:17] kalle@php.net
Namespace names are the same as class names, you cannot use a reserved
keyword as a name anywhere. I think don't we should say on every single
language construct page that you may not use a reserved keyword in a
definition as it makes perfectly sense already.
Adding such things in future things wouldn't be something I would count
on, as it creates many complications since we now have to do extra
checks when we hit a string like:
$default = new Default;
It can also create very unreadable code if you mix language keywords
with API names, and should just be avoided.
------------------------------------------------------------------------
[2009-10-24 18:49:17] swquinn at gmail dot com
Follow-up: Sorry for the double post. I went back and reviewed the
documentation. Still couldn't find anything, but on the manual page
"Defining Namespaces"
(http://www.php.net/manual/en/language.namespaces.definition.php) there
was a user comment that I missed when going through the documentation
that mentions this issue as well.
If its not in the actual manual, it would be great to note this some
place!
And, thank you for your response!
------------------------------------------------------------------------
[2009-10-24 18:44:52] swquinn at gmail dot com
Is there any possibility in the future (e.g. PHP 6+) that the
acceptable vocabulary for namespaces could be expanded so that the use
of a keyword in the namespace doesn't throw a parse error?
------------------------------------------------------------------------
[2009-10-24 02:00:09] johannes@php.net
This is expected.
Didn't check the docs, maybe this can be made clearer.
------------------------------------------------------------------------
[2009-10-24 01:34:07] swquinn at gmail dot com
Description:
------------
Using a PHP language token, or syntactic keyword within a namespace
causes a Parse error to be thrown by PHP. There is no documentation
anywhere (that I could find) indicating whether keywords are permitted
as part of a namespace name.
If they are not, it would be nice if this is documented.
If they should be, then this is clearly a defect.
It would be _nice_ a keyword could contain any words (language syntax
or otherwise).
Reproduce code:
---------------
<?php
namespace my\default\ns;
class Foo {
public function bar() {
return 0;
}
}
$foo = new Foo();
echo $foo->bar();
?>
Expected result:
----------------
0
Actual result:
--------------
Parse error: syntax error, unexpected T_DEFAULT, expecting T_STRING in
D:\PHP\tests\test.php on line 2
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=49982&edit=1