thekid/rfc — Issue #80: RFC 0080: Anonymous class creation
Author: thekid
Created: 2011-10-09 14:55:51+00:00
State: closed
Labels: implemented, rfc

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

Comments
====
- friebe, Mon Nov 27 12:11:33 CET 2006
I think we should increase only the minor version because this
functionality is intended for user source only and not for core
components. Because no core components use this functionality,
a major version jump seems not to make sense.