rfc:namespaceref

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
Last revisionBoth sides next revision
rfc:namespaceref [2008/10/14 21:10] stasrfc:namespaceref [2008/10/14 22:43] stas
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 17: Line 17:
  
 Inside namespace, class definition can be used as: Inside namespace, class definition can be used as:
-  - Imported name - name mentioned in "use" statement as sortcut for the full name. Imported name can be also a prefix to further qualified name.+  - Imported name - name mentioned in "use" statement as shortcut for the full name. Imported name can be also a prefix to further qualified name.
 <code php> <code php>
 use Foo::Bar as Fubar; use Foo::Bar as Fubar;
 $a = new Fubar::Baz(); $a = new Fubar::Baz();
 </code> </code>
-  - Full name not mentioned in import - Foo::Bar::Baz - take at the face value. Special cases of this are: +  - Full name not mentioned in import - ''Foo::Bar::Baz'' - take at the face value. Special cases of this are: 
-    - ::Foo - global name +    - ''::Foo'' - global name, i.e. explicit reference to non-namespaced class inside namespace 
-    - namespace::Foo - name explicitly referring to current namespace +    - ''namespace::Foo'' - name explicitly referring to current namespace 
-  - Unqualified name 'Foonot mentioned in import - resolved as namespace::Foo.+  - Unqualified name "Foonot mentioned in import - resolved as ''namespace::Foo''.
  
 ==== Pro ==== ==== Pro ====
Line 39: Line 39:
 Functions and constants defined in the namespace are prefixed with the namespace name.  Functions and constants defined in the namespace are prefixed with the namespace name. 
  
-Quailified function call A::B::C() is resolved as follows:+Quailified function call ''A::B::C()'' is resolved as follows:
   - All possible "use" imports are resolved against A (first component).   - 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. +  - 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".+  - Otherwise, treat the call as call to method "Cof the class "A::B".
  
-Unqualified function call foo() inside namespace resolved as follows:+Unqualified function call ''foo()'' inside namespace resolved as follows:
   - If internal function "foo" exists - call the function   - If internal function "foo" exists - call the function
-  - Otherwise, call the function namespace::foo+  - Otherwise, call the function ''namespace::foo''
  
 Constants resolved in a way identical to functions.  Constants resolved in a way identical to functions. 
  
-New syntax for static access is introduced: using Name->Member is the same as Name::Member, e.g.:+New syntax for static access is introduced: using ''Name->Member'' is the same as ''Name::Member'', e.g.:
 <code> <code>
 ClassName->Foo() - static method call ClassName->Foo() - static method call
Line 56: Line 56:
 ClassName->Foo - class constant access ClassName->Foo - class constant access
 </code> </code>
 +
 +==== Pro ====
 +  * The last syntax allows to call static methods unambiguously
 +  * Functions and constants supported
 +
 +==== 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
  
 ===== See also ===== ===== See also =====
rfc/namespaceref.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1