1) Lack of cohesiveness of name resolution rules

Why is this an argument against: name resolution rules with namespaces
change completely the way names are resolved in PHP.

How does it affects: this breaks the explicitness of names in PHP. It will
affect code debugging and review.

Example:

<?php
.
.
.
// many lines before this
foo(); // is it a global function or a namespaced function?
A::foo(); // is it a member function? a namespaced function? a global class?
a namespaced class?
?>

Suggestions:

a) Introduce a special name to refer to the current namespace (as self::
works for the current class). All namespace access should be explicit:

<?php
.
.
.
// many lines before this
foo(); // a call to global foo() and nothing else
namespace::foo(); // a call to foo() in the current namespace
?>

b) Name aliasing with use should only generate namespaces aliases:

<?php
use Really::Long::Namespace as Short;
$object = new Short::AClass();
use Really::Long::Namespace::AClass; // should make AClass an alias to a
namespace, not a class
$object = new AClass(); // should look for global AClass
?>

c) Solve ambiguity generated by using :: as namespace separator (see
following argument)

----

2) Using :: as namespace separator generates ambiguity

Why is this an argument against: :: is also used for static member access
and becomes ambiguous when used together

How does it affects: same as (1).

Example:

<?php
...
Foo::test(); // a member function? a namespaced function?
?>

Suggestions:

a) find a way to clearly distinguish the namespace part of a name (I've
currently no suggestions on what operator to use without seriously harming
readability).

b) OR restrict the namespace application to classes (if only classes can be
namespaced there is no ambiguity, although I must admit I don't like this
option).

----

3) Enforcing a scope is something that has no precedence in the PHP language


What: the namespace statement and the import statement (use) has an enforced
scope to the file.

Why is this an argument against: there was not a construct that works as
this one in PHP.

How does it affects: it changes the way we work with code. We now how to be
conscious of declarations enforced on the whole file, not because we messed
up with scopes but because we didn't have a choice.

Suggestions:

a) Allow the before mentioned statements to have scope managed by the coder.

b) Disallow the scopeless use of those statements (which is implicitly
scoped to the file).

c) If bracketed namespaces are a no-go, consider the possibility of
declaring the full name of the namespaced element in its definition:

<?php
class Name::Space::ClassName {
...
}
?>

Which should work as:

<?php
namespace Name::Space {
  class ClassName {
  ...
  }
}
?>

Reply via email to