rfc:namespacecurlies

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
rfc:namespacecurlies [2008/08/31 12:37] hellyrfc:namespacecurlies [2008/08/31 13:13] helly
Line 52: 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/require.
 +
 +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
 +namespce foo;
 +function test{} {
 +  echo __NAMESPACE__ . "\n";
 +  include 'bar.php';
 +  echo __NAMESPACE__ . "\n";
 +}
 +
 +--bar.php
 +// namespace bar;
 +echo __NAMESPACE__ . "\n";
 +
 +The above shows 'foo', '', 'foo'. Further more the namespace statement in bar.php is legal and leads to 'foo', 'bar', foo'. It also means we kind of allow nested namespaces. The reason we need to allow include/require inside functions/methods is to support the common way of dynamic module loading.
 +
 +We do not want to add special forms of require/include that do or not do carry over the current namespace and disallow namespace declarations if carried over.
 +
 +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("F", C::c);'
 +
 +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://felipe.ath.cx/diff/namespace-braces-5_3.diff|patch]].+We propose to add namespaces as block structures and drop 'namespace foo;' in favor of 'namespace foo: ; endnamespace;', as in this [[http://felipe.ath.cx/diff/namespace-braces-5_3.diff|patch]]. The tests are provided in a [[http://felipe.ath.cx/diff/ns-tests-53.diff|second patch]].
  
 ===== Changelog ===== ===== Changelog =====
rfc/namespacecurlies.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1