This is an old revision of the document!
Request for Comments: How to write RFCs
- Version: 1.0
- Date: 2008-08-31
- Status: Under Discussion
- First Published at: http://wiki.php.net/rfc/namespacecurlies
This RFC deals with the open questions in regards to namespaces that came up during the alpha release of PHP 5.3.
The following issues have been identified:
- The keyword 'namespace' itself.
- Namespace as kind of labels versus namespaces as blocks.
- Statements outside namespaces.
- Nested namespace support.
The keyword 'namespace
The keyword has been discussed several times and even though a real explanation has not been found the agreement is that we think of namespaces literally. Furthermore the names are in no way related to the file system structure as is with Java packages for instance. The immediate conclusion is that we stick to the keyword. This also has the advantage that many people have seen namespace as a reserved keyword even when it was not a reserved keyword. This part is thus not open for discussion.
Why do we need namespace blocks?
We need to describe how we think of namespaces. Right now the PHP runtime treats namespaces as simple text replacements. That is the runtime will only resolve names in the current and global namespace. With this in mind it does not matter whether we do namespaces as blocks or labels. This difference comes from experience, comparison to existing implementations, expectation and consistency.
- PHP has labels and blocks.
- Labels do not influence the code after the label.
- PHP also offers alternative syntax for control structures. This looks like 'if (true): echo “then”;'. This alternative syntax is being avoided by most developers today. In fact every once in a while people ask to remove support for it.
- Some people require to indent anything within curly braces (often because of their editor settings).
- Nearly all C++ editors are set to not indent on namespaces.
- Java and C++ are the closest, wide spread languages that support namespaces.
- C++ uses the keywords 'namespace' and 'use' and only allows blocks. Netsing and multiple namespaces are allowed.
- Java uses the keywords 'package' and 'import' and requires the file system to reflect what is defined in the code. Packages are defined in a single statement and only one package is allowed per file.
- Usually PHP tries to be close to an existing implementation.
- Many developers were expecting to simply implement what was done during PHP 5.0 alpha phase (namespace as in C++).
- With the new implementation and no blocks, many people expected one namespace per file.
- Since fewer files means faster execution, many people simply concatenate PHP scripts. Their expectation is to be able to do this for code that uses namespaces as well.
- PHP will add Phar archive support and thus does not really require source concatenation any longer.
- The common syntax is using blocks for anything that influences following code.
- The alternative is to use 'namespace name:' rather than 'namespace name; /*…*/ endnamespace;' is done for all other alternate forms.
- Only control structures can be followed by a statement without either ';' or ':', however they only allow a single statement.
Statements outside namespaces
Nested namespace support
Proposal and Patch
We propose to add namespaces as block structures, as in this patch.