<commit_before>RFC 0037: Ability to fully qualify class names
========================================================================
$Id$

@authors: friebe
@created: Fri Sep  2 18:00:18 CEST 2005
@status: draft
@category: <core>

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.

Functionality
-------------
A class declares being within a package by setting the variable $package
and by supplying its classname in fully-qualified notation, using the 
middle dot () as separator.

Example (Declaration)
~~~~~~~~~~~~~~~~~~~~~
<?php
  uses('util.Date');

  $package= 'info.binford6100';

  class infobinford6100Date extends Date {
  
    function toString() {
      return 'More Power: '.parent::toString();
    }
  }
?>

Example (Usage)
~~~~~~~~~~~~~~~
<?php
  require('lang.base.php');
  uses('info.binford6100.Date');
  
  echo xp::stringOf(new infobinford6100Date()), "\n";
?>

Output of above example
~~~~~~~~~~~~~~~~~~~~~~~
<pre>
  More Power: Fri, 02 Sep 2005 17:59:44 +0200
</pre>

Notes
~~~~~
<pre>
- 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

- The implements() syntax will change for fully qualified classes but 
  will be backwards-compatible for non-fully qualified ones:
  
  // Works only in non-fully qualified classes
  implements(__FILE__, 'util.log.Traceable');
  
  // Works in fully qualified classes:
  implements('infobinford6100TraceableObject', 'util.log.Traceable');
  
  // ...and in non-fully qualified ones:
  implements('TraceableObject', 'util.log.Traceable');
</pre>

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
------------
n/a

Related documents
-----------------
- http://xp-framework.net/downloads/rfc0037.diff
  Patch implementing this RFC

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?
<EOF><commit_msg>- Add comment on current status<commit_after>RFC 0037: Ability to fully qualify class names
========================================================================
$Id$

@authors: friebe
@created: Fri Sep  2 18:00:18 CEST 2005
@status: draft
@category: <core>

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.

Functionality
-------------
A class declares being within a package by setting the variable $package
and by supplying its classname in fully-qualified notation, using the 
middle dot () as separator.

Example (Declaration)
~~~~~~~~~~~~~~~~~~~~~
<?php
  uses('util.Date');

  $package= 'info.binford6100';

  class infobinford6100Date extends Date {
  
    function toString() {
      return 'More Power: '.parent::toString();
    }
  }
?>

Example (Usage)
~~~~~~~~~~~~~~~
<?php
  require('lang.base.php');
  uses('info.binford6100.Date');
  
  echo xp::stringOf(new infobinford6100Date()), "\n";
?>

Output of above example
~~~~~~~~~~~~~~~~~~~~~~~
<pre>
  More Power: Fri, 02 Sep 2005 17:59:44 +0200
</pre>

Notes
~~~~~
<pre>
- 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

- The implements() syntax will change for fully qualified classes but 
  will be backwards-compatible for non-fully qualified ones:
  
  // Works only in non-fully qualified classes
  implements(__FILE__, 'util.log.Traceable');
  
  // Works in fully qualified classes:
  implements('infobinford6100TraceableObject', 'util.log.Traceable');
  
  // ...and in non-fully qualified ones:
  implements('TraceableObject', 'util.log.Traceable');
</pre>

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
------------
n/a

Related documents
-----------------
- http://xp-framework.net/downloads/rfc0037.diff
  Patch implementing this RFC

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.

<EOF>
{'fraction_non_alphanumeric': 0.1544477028347996, 'fraction_numerical': 0.035842293906810034, 'mean_word_length': 3.4292929292929295, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '607256', 'n_tokens_mistral': 1920, 'n_tokens_neox': 1703, 'n_words': 701}