Table of Contents

Namespace refinement proposals

The purpose of the RFC is to summaries current proposals regarding namespaces.

Introduction

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:

  1. Imported name - name mentioned in “use” statement as shortcut for the full name. Imported name can be also a prefix to further qualified name.
use Foo::Bar as Fubar;
$a = new Fubar::Baz();
  1. Full name not mentioned in import - Foo::Bar::Baz - take at the face value. Special cases of this are:
    1. ::Foo - global name, i.e. explicit reference to non-namespaced class inside namespace
    2. namespace::Foo - name explicitly referring to current namespace
  2. Unqualified name “Foo” not mentioned in import - resolved as namespace::Foo.

Pro

Contra

Well, duh, no functions :)

Namespaces with functions/constants

As the above, plus:

Functions and constants defined in the namespace are prefixed with the namespace name.

Quailified function call A::B::C() is resolved as follows:

  1. All possible “use” imports are resolved against A (first component).
  2. If function by name “A::B::C” exists, take A::B::C as the function name and do the regular function call.
  3. Otherwise, treat the call as call to method “C” of the class “A::B”.

Unqualified function call foo() inside namespace resolved as follows:

  1. If internal function “foo” exists - call the function
  2. Otherwise, call the function namespace::foo

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.:

ClassName->Foo() - static method call
ClassName->$Foo - static property access
ClassName->Foo - class constant access

Pro

Contra

See also

Please see also Namespace RFC for more details