rfc:namespacecurlies
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
rfc:namespacecurlies [2008/08/31 13:11] – helly | rfc:namespacecurlies [2008/08/31 15:37] – fix link bjori | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Request for Comments: | + | ====== Request for Comments: |
* Version: 1.0 | * Version: 1.0 | ||
* Date: 2008-08-31 | * Date: 2008-08-31 | ||
Line 11: | Line 11: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | During alpha phase of PHP 5.0 ther was a namespace implementation that was very close to the one of C++. Because an inconsistency between namespace separator '::' | + | During alpha phase of PHP 5.0 there was a namespace implementation that was very close to the one of C++. Because an inconsistency between namespace separator '::' |
The following issues have been identified: | The following issues have been identified: | ||
Line 34: | Line 34: | ||
- Nearly all C++ editors are set to not indent on namespaces. | - Nearly all C++ editors are set to not indent on namespaces. | ||
- | | + | |
- Java and C++ are the closest, wide spread languages that support namespaces. | - Java and C++ are the closest, wide spread languages that support namespaces. | ||
- | - C++ uses the keywords ' | + | - C++ uses the keywords ' |
- Java uses the keywords ' | - Java uses the keywords ' | ||
Line 44: | Line 44: | ||
- With the new implementation and no blocks, many people expected one namespace per file. | - 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. | - 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 [[php.net/ | + | - PHP will add [[http://php.net/ |
* Consistency: | * Consistency: | ||
Line 50: | Line 50: | ||
- The alternative is to use ' | - The alternative is to use ' | ||
- Only control structures can be followed by a statement without either ';' | - Only control structures can be followed by a statement without either ';' | ||
+ | |||
+ | * Issues: | ||
+ | - When concatenating a file with a namespace and one without a namespace, the second file gets pulled into the namespace unless the namespace used curly braces. | ||
==== Statements outside namespaces ==== | ==== Statements outside namespaces ==== | ||
Line 58: | Line 61: | ||
--foo.php | --foo.php | ||
- | namespce | + | namespace |
- | function test{} { | + | function test{} { |
- | echo __NAMESPACE__ . " | + | echo __NAMESPACE__ . " |
- | include ' | + | include ' |
- | echo __NAMESPACE__ . " | + | echo __NAMESPACE__ . " |
- | } | + | } |
--bar.php | --bar.php | ||
- | // namespace bar; | + | |
- | echo __NAMESPACE__ . " | + | echo __NAMESPACE__ . " |
The above shows ' | The above shows ' | ||
Line 75: | Line 78: | ||
This leaves us with define() as well as with require and include without carrying over the current namespace. For define we clearly allow name resolution: | This leaves us with define() as well as with require and include without carrying over the current namespace. For define we clearly allow name resolution: | ||
- | $> php -r 'class C { const c=42; } define(" | + | $> php -r 'class C { const c = 42; } define(" |
This in some way also applies to require and include because the both allow constants and variables. However define is a function and does not allow special treatment in the parser. Require and include on the other hand are parser states and take single expression as parameter. This expression can easily be turned into two different things. A full expression and a string only. The string only version can be allowed outside namespaces. | This in some way also applies to require and include because the both allow constants and variables. However define is a function and does not allow special treatment in the parser. Require and include on the other hand are parser states and take single expression as parameter. This expression can easily be turned into two different things. A full expression and a string only. The string only version can be allowed outside namespaces. | ||
==== Nested namespace support ==== | ==== Nested namespace support ==== | ||
+ | |||
+ | PHP uses simple text replacement for namespace resolution and thus can easily allow nested namespaces without any technical issue whatsoever. | ||
===== Proposal and Patch ===== | ===== Proposal and Patch ===== | ||
We propose to add namespaces as block structures and drop ' | We propose to add namespaces as block structures and drop ' | ||
+ | |||
+ | In a second step nesting namespaces should be supported. This can easily be done by simply removing the corresponding error messages. | ||
===== Changelog ===== | ===== Changelog ===== |
rfc/namespacecurlies.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1