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 13:11] hellyrfc:namespacecurlies [2008/08/31 13:16] helly
Line 58: Line 58:
  
 --foo.php --foo.php
-namespce foo; +  namespce foo; 
-function test{} { +  function test{} { 
-  echo __NAMESPACE__ . "\n"; +    echo __NAMESPACE__ . "\n"; 
-  include 'bar.php'; +    include 'bar.php'; 
-  echo __NAMESPACE__ . "\n"; +    echo __NAMESPACE__ . "\n"; 
-}+  }
  
 --bar.php --bar.php
-// namespace bar; +  // namespace bar; 
-echo __NAMESPACE__ . "\n";+  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. 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.
Line 75: Line 75:
 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("F", C::c);'+$> 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. 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 '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]]. 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]].
 +
 +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