thekid/rfc — Issue #70: RFC 0070: Extend ClassLoader::defineClass() 
Author: thekid
Created: 2011-10-09 14:51:50+00:00
State: open

Scope of Change
====
Method ClassLoader::defineClass() will be extended to not only take a classname
and the class implementation, but also a third and forth argument, the parent
class and a list of implemented interfaces.

If defineClass() is invoked with two arguments, the current behaviour will be
used, if invoked with four arguments instead, the new behaviour will be used.

Rationale
====
XP's implements() method takes a filename as first argument and the name
of the implemented interface as second. The to-be-defined class does not have
a separate filename, so one has to trick to make it work.

Functionality
====

Current
----
The current implementation takes two arguments:
* string classname
* string bytes

```php
defineClass($name, 'class ShortName extends Object {
function __construct() {
// ...
}
} implements("ShortName.class.php", "Constructable");');
?>
```

New
----
The new implementation takes four arguments
* string classname
* string parent
* string[] interfaces
* string bytes

```php
defineClass($name, $parent, $interfaces, '{
function __construct() {
// ...
}
}');
?>
```

If only two arguments are passed, the old implementation will be executed.

Security considerations
====
n/a

Speed impact
====
n/a

Dependencies
====
n/a

Related documents
====
- http://xp-framework.net/rfc/contrib/rfc0070.diff
Patch against skeleton/

Comments
====
- friebe, Wed Aug 23 14:50:17 CEST 2006
Extends this RFC to include being able to pass classname and parent class

- kiesel, Thu Aug 24 16:17:46 CEST 2006
A more complex API to define classes at runtime will be added later through a
new RFC. Main focus for this RFC is to remove the need to mess with the
implements() function when defining a new class that implements an interface.

- kiesel, Thu Aug 24 16:17:46 CEST 2006
Because this RFC is BC-break-free, I shortened the discussion period to
tomorrow noon.