rfc:namespaceresolution

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:namespaceresolution [2008/10/31 17:51] lsmithrfc:namespaceresolution [2008/11/04 19:18] lsmith
Line 1: Line 1:
-====== Namespace identifier resolution RFCs ====== +====== Non fully qualified namespaced identifier resolution RFCs ====== 
-  * Version: 1.0.1+  * Version: 1.1.0
   * Date: 2008-10-30   * Date: 2008-10-30
   * Author: Lukas Smith <smith@pooteeweet.org>   * Author: Lukas Smith <smith@pooteeweet.org>
Line 6: Line 6:
   * First Published at: http://wiki.php.net/rfc/namespaceresolution   * First Published at: http://wiki.php.net/rfc/namespaceresolution
  
-This RFC discusses the way identifiers inside a namespace are to be resolved. +This RFC discusses the way identifiers inside a namespace are to be resolved that are not fully qualified.
 ===== Introduction ===== ===== Introduction =====
  
Line 20: Line 19:
 ?> ?>
 </code> </code>
-Obviously its important that we make a conscious decision for these questions. Depending on how we approach this, users might unintentionally trigger autoload, call functions in the global namespace they did not expect or they could run into trouble when trying to migrate existing code to namespaces. 
  
-Obviously one way to avoid this is via an explicit "use" statement or by fully qualifying the name+Its important that we make a conscious decision for these questions. Depending on how we approach this, users might unintentionally trigger autoload, call functions in the global namespace they did not expect or they could run into trouble when trying to migrate existing code to namespaces. 
 + 
 +One way to avoid this is via an explicit "use" statement or by fully qualifying the name
  
 <code php> <code php>
Line 34: Line 34:
 </code> </code>
  
-While there is obviously no way to magically import the right things all namespaces, we do have the option of automatically falling back into the  global namespace if the identifier does not resolve in the local namespace. This RFC details some alternative approaches for this as well as how things would be like if such a fallback would not exist.+While there is no way to magically import the right things all namespaces, we do have the option of automatically falling back into the  global namespace if the identifier does not resolve in the local namespace. This RFC details some alternative approaches for this as well as how things would be like if such a fallback would not exist.
  
 ===== Possible approaches ===== ===== Possible approaches =====
Line 99: Line 99:
   - Classes still need fully qualified names   - Classes still need fully qualified names
  
-=== Only for classes ===+=== Only for classes (autoload first) ===
  
 Assumption: People want to overload global classes Assumption: People want to overload global classes
  
-Notes: By throwing an E_NOTICE when a fallback occurs, the performance issues become more manageable, but it would reduce the feasibility of overloading.+Notes: By throwing an E_NOTICE when a fallback occurs, the performance issues become more manageable, but it would reduce the feasibility of overloading. Also if instead of checking autoload before global, one could first check global before falling back to autoload. This prevents performance issues, but would raise issues with the load order similar to functions/constants.
  
 == Advantages == == Advantages ==
Line 130: Line 130:
 Assumption: People want to easily migrate their existing code and beginners should not have to know (as much about) if they are coding inside a namespace or not. Assumption: People want to easily migrate their existing code and beginners should not have to know (as much about) if they are coding inside a namespace or not.
  
-Notes: By throwing an E_NOTICE when a fallback occurs, the performance issues become more manageable, but it would reduce the feasibility of overloading. Also note that if functions (and constants) would be removed from namespaces, then some of the disadvantages would be removed as functions (and constants) would always directly reference the global namespace.+Notes: By throwing an E_NOTICE when a fallback occurs, the performance issues become more manageable, but it would reduce the feasibility of overloading. Also note that if functions (and constants) would be removed from namespaces, then some of the disadvantages would be removed as functions (and constants) would always directly reference the global namespace. Also if instead of checking autoload before global, one could first check global before falling back to autoload. This prevents performance issues for classes, but would raise issues with the load order similar to functions/constants, but means things would be consistent in the sense that overloading requires defining the relevant identifiers ahead of use for everything (classes/functions/constants).
  
 == Advantages == == Advantages ==
Line 160: Line 160:
 ===== Changelog ===== ===== Changelog =====
  
 +- from 1.0 to 1.1: added variant with 1) ns 2) global 3) autoload
 - from 1.0 to 1.0.1: tweaked examples - from 1.0 to 1.0.1: tweaked examples
 - from 0.9 to 1.0: added some examples, added note about use statement, fixed some language issues - from 0.9 to 1.0: added some examples, added note about use statement, fixed some language issues
rfc/namespaceresolution.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1