xp-framework/rfc — Issue #30: Overloaded methods in lang.reflect.Proxy
Author: thekid
Created: 2011-10-17 15:41:13+00:00
State: closed
Labels: framework, implemented

Scope of Change
====
Add a new functionality to method getProxyClass() of lang.reflect.Proxy
class. This functionality will add the ability to design proxy classes
by a new annotation "@overloaded" being able to give method calls a
variable number of arguments, e.g. for overloaded methods in java.

Rationale
====
When creating proxy instances of a java class there is no way in php to
overload methods. A java bean class implementing the following methods

public string sayHello() {}
public string sayHello(String name) {}

would cause a "Fatal error: Cannot redeclare sayHello()" when generating
an Interface for that class. Thus when creating Interfaces with
overloaded methods, the overloaded method must be declared only once
with a variable number of parameters.

Functionality
====
Overloaded methods in Interfaces will be declared as follows:

```php

```

The annotation "@overloaded" indicates that there are several methods
using the same name and describes the different types of parameters of
those methods. The lang.reflect.Proxy class then generates special code
for those kind of classes to cover all possible calls of that method:

```php
_h->invoke($this, 'sayHello', array());
case 1: return $this->_h->invoke($this, 'sayHello', array($_0));
default: return throw(new IllegalArgumentException(
'Illegal number of arguments'
));
}
}
}
?>
```

Security considerations
====
n/a

Speed impact
====
Slightly decreases speed of generating proxy classes.

Dependencies
====
none

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