rfc:namespaceref

Differences

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

Link to this comparison view

Next revision
Previous revision
rfc:namespaceref [2008/10/14 20:49] – created stasrfc:namespaceref [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 1: Line 1:
-====== Request for Comments: How to write RFCs ======+====== Namespace refinement proposals ======
   * Version: 1.0   * Version: 1.0
   * Date: 2008-03-06   * Date: 2008-03-06
Line 6: Line 6:
   * First Published at: http://wiki.php.net/rfc/namespaceref   * First Published at: http://wiki.php.net/rfc/namespaceref
  
-This RFC is a template other people can use to write their own RFCs+The purpose of the RFC is to summaries current proposals regarding namespaces.  
 +  
 ===== Introduction ===== ===== Introduction =====
  
-The purpose of RFCs are to work collaboratively towards specification and finally an implementation of an idea.+So far I have two proposals for resolving current namespace debates - one that includes namespaced function and one that does not. This RFC assumes you are familiar with the topic of namespaces in general.  
 + 
 +===== Namespaces without functions/constants ===== 
 + 
 +All new functionality relates only to classes. Any code is allowed inside namespace, but only class definitions and references to classes is influenced by it. Class defined in the namespace is prefixed by it's name.  
 + 
 +Inside namespace, class definition can be used as: 
 +  - Imported name - name mentioned in "use" statement as shortcut for the full name. Imported name can be also prefix to further qualified name. 
 +<code php> 
 +use Foo::Bar as Fubar; 
 +$a = new Fubar::Baz(); 
 +</code> 
 +  - Full name not mentioned in import - ''Foo::Bar::Baz'' - take at the face value. Special cases of this are: 
 +    - ''::Foo'' - global name, i.e. explicit reference to non-namespaced class inside namespace 
 +    - ''namespace::Foo'' - name explicitly referring to current namespace 
 +  - Unqualified name "Foo" not mentioned in import - resolved as ''namespace::Foo''
 + 
 +==== Pro ==== 
 +  * Most (not all, I know, but most) of the use cases for namespaces are in the OO realm, and most of the problems they are to serve come from that realm too. So at least initially most of the active users, which wait for it impatiently, are OO users, and classes are the thing the care the most about. 
 +  * Everything becomes so much simpler with only classes. Classes and functions have very different usage patterns in PHP, so if we try to serve them both we inevitably encounter some "inconsistencies" in how they are served, because of the different usage patterns. 
 +==== Contra ==== 
 +Well, duh, no functions :)
  
-==== Why do we need RFCs? ====+===== Namespaces with functions/constants =====
  
-They serve to keep a summary of on going discussions. This way people can keep an overview of the state of the discussion. Even if never put into place in the endthey also serve as a historical log of discussions that is much easier to read compared to mailinglist threads.+As the aboveplus:
  
-===== Common Misconceptions =====+Functions and constants defined in the namespace are prefixed with the namespace name. 
  
-RFCs do not in any way replace discussions on the mailing list.+Quailified function call ''A::B::C()'' is resolved as follows: 
 +  - All possible "use" imports are resolved against A (first component). 
 +  - If function by name "A::B::C" exists, take ''A::B::C'' as the function name and do the regular function call. 
 +  - Otherwise, treat the call as call to method "C" of the class "A::B".
  
-===== Proposal and Patch =====+Unqualified function call ''foo()'' inside namespace resolved as follows: 
 +  - If internal function "foo" exists - call the function 
 +  - Otherwise, call the function ''namespace::foo''
  
-Nothing needs to be patched here. Just use this template at your discretion.+Constants resolved in a way identical to functions
  
-==== Rejected Features ====+New syntax for static access is introduced: using ''Name->Member'' is the same as ''Name::Member'', e.g.: 
 +<code> 
 +ClassName->Foo() - static method call 
 +ClassName->$Foo - static property access 
 +ClassName->Foo - class constant access 
 +</code>
  
-Automated voting system.+==== Pro ==== 
 +  * The last syntax allows to call static methods unambiguously 
 +  * Functions and constants supported
  
-==== More about RFCs ====+==== Contra ==== 
 +  * The model is more complex and may be confusing for the new users. 
 +  * Unqualified name resolutions for classes and functions/constants are slightly different due to the different usage patterns. 
 +  * New syntax for static access
  
-http://en.wikipedia.org/wiki/Request_for_Comments+===== See also =====
  
-===== Changelog =====+Please see also [[http://wiki.php.net/rfc/namespaces| Namespace RFC]] for more details
  
  
  
rfc/namespaceref.1224017367.txt.gz · Last modified: 2017/09/22 13:28 (external edit)