xp-framework/rfc — Issue #80: Anonymous class creation
Author: thekid
Created: 2011-10-17 15:52:10+00:00
State: closed
Labels: framework, implemented

Scope of Change
====
A way to create anonymous instances of interfaces and abstract classes will
be provided.

Rationale
====
Throw-away classes / migration.

Functionality
====

newinstance() declaration
----

```
&lang.Object newinstance(
string classname,
mixed[] args,
string bytes
)

Arguments:
- baseclass is the fully qualified class name of the interface to
implement or the abstract class to inherit from.

- args are the constructor arguments

- source is the class' sourcecode, including a leading "{" and a
trailing "}"

Creating an anonymous instance will bail with an error...
- ...in case the class "classname" cannot be found.

- ...in case the source code specified by the bytes argument doesn't
parse.

- ...in case classname refers to an interface and the declared class
fails to implement the interface.

Creating an anonymous instance of an interface:
----

```php
properties= &$properties;
}

function accept(&$element) {
return (
4 == sscanf(basename($element->getURI()), "%[^-]-%d-%d-%d.log", $type, $y, $m, $d) &&
$this->properties->hasSection($type)
);
}
}');
?>
```

Security considerations
====
n/a

Speed impact
====
Slower than declaring real classes.

Dependencies
====
This patch will increase the XP framework's minor version (4.1.0)

Related documents
====
- http://experiments.xp-framework.net/?people,friebe,newinstance
Experiment

- http://experiments.xp-framework.net/?people,friebe,jay,demo/newinstance.xp
XP language equivalent

- http://xp-framework.net/rfc/contrib/rfc0080.diff
Patch