Ability to fully qualify class names

  Status: implemented,  Tue May 8 17:24:45 2007
  • Created: 2005-09-02 18:00:18+0200
  • Categories: <core>
  • Author: friebe

Scope of Change

Classes can be optionally declared with their fully qualified name. Class loading and reflection semantics will not change, though.


Rationale

Avoid name clashes. Especially useful for supporting classes that never appear in a new statement or any other place their full name needs to be typed, like remote interfaces.

Functionality

A class declares being within a package by setting the variable $package.

Example (Declaration)

  uses('util.Date');

$package= 'info.binford6100';

class info·binford6100·Date extends Date {

function toString() {
return 'More Power: '.parent::toString();
}
}

Example (Usage)

  require('lang.base.php');
uses
('info.binford6100.Date');

echo xp::stringOf
(new info·binford6100·Date()), "\n";

Output of above example

  More Power: Fri, 02 Sep 2005 17:59:44 +0200

Notes

- For existing classes, nothing will change

- Fully qualified classes can only be referenced by their fully qualified
  name, non-fully-qualified classes can only be referenced by their non-
  qualified name

- XPClass::forName() can no longer support unqualified class names. What
  does XPClass::forName('Date') return for the above example?

Security considerations

n/a

Speed impact

Core will become a bit slower because it will need to distinguish between the two cases:

  1. A class is declared with its fully qualified name
  2. A class is declared non-fully qualified

Dependencies

- RFC #0121

Note: This will change the version number to 5.5.0

Related documents

- http://experiments.xp-framework.net/?arena,classloaders Experiment

Comments

- friebe, Fri Sep 2 18:08:18 CEST 2005 The patch still needs quite some work. All the array_search() / in_array() calls to look up class names are slow.

- friebe, Mon Sep 12 10:17:23 CEST 2005 The patch does not work correctly for situations in which class A uses() B and B uses() A, producing an endless loop.

- friebe, Tue Oct 4 23:48:42 2005 Fixed the patch - net.xp_framework.unittest.reflection.ReflectionTest unittest now works

- friebe, Tue Oct 4 23:59:54 2005 Maybe implements() should not be backwards compatible? BC causes performance problems here... or should it warn about usage of the old syntax and give note that we'll deprecate sooner or later?

- friebe, Wed Dec 28 16:10:19 CET 2005 Revamped lang.base.php and lang/ClassLoader.class.php committed to experiments/people/friebe/rfc0037. All tests in util/test/core.ini pass.

- friebe, Mon Feb 20 13:05:21 CET 2006 New patch available at above location. Also passes all tests.

- friebe, Fri Feb 16 12:06:31 CET 2007 Migrated to PHP5, rewrote parts of this RFC

<EOF>


Table of contents