rfc:namespacecurlies
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:namespacecurlies [2008/08/31 12:31] – helly | rfc:namespacecurlies [2008/08/31 13:26] – Add title felipe | ||
---|---|---|---|
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 10: | Line 10: | ||
===== Introduction ===== | ===== Introduction ===== | ||
+ | |||
+ | 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 32: | 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 50: | Line 52: | ||
==== Statements outside namespaces ==== | ==== Statements outside namespaces ==== | ||
+ | |||
+ | PHP needs to support compiler caches and their way of name resolution. This is at the moment bound to filenames and as a consequence we cannot allow any code that potentially requires name lookup. This means we could only allow statements outside namespaces that either never do name lookup or we need special forms of those that disallow name lookup outside namespaces. In fact this seems only relevant to define() and include/ | ||
+ | |||
+ | Include as well as require do not carry over namespace information. This is a problematic as it allows for functions with mixed inner namespace resolution: | ||
+ | |||
+ | --foo.php | ||
+ | namespace foo; | ||
+ | function test{} { | ||
+ | echo __NAMESPACE__ . " | ||
+ | include ' | ||
+ | echo __NAMESPACE__ . " | ||
+ | } | ||
+ | |||
+ | --bar.php | ||
+ | // namespace bar; | ||
+ | echo __NAMESPACE__ . " | ||
+ | |||
+ | The above shows ' | ||
+ | |||
+ | We do not want to add special forms of require/ | ||
+ | |||
+ | 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(" | ||
+ | |||
+ | 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, as in this [[http:// | + | We propose to add namespaces as block structures |
+ | |||
+ | 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