xp-framework/rfc — Issue #164: Exceptions for XPClass::get*()
Author: thekid
Created: 2011-10-17 16:02:08+00:00
State: closed
Labels: framework, implemented

Scope of Change
====
The following methods in lang.XPClass will throw exceptions instead of
returning NULL for the case the respective element is not found:
* getConstructor()
* getMethod(string name)
* getField(string name)

Rationale
====
Allow for chaining, be consistent with other APIs (if a hasX method exists,
the getX method will throw an exception) and the getAnnotation() method.

Functionality
====
The following can be written in a more concise way:

```php
getMethod('main');
if (!$m) throw new ElementNotFoundException('No "main" method');
$m->invoke(NULL, array($args));
?>
```

New:

```php
getMethod('main')->invoke(NULL, array($args));
?>
```

BC break
----
The following will no longer work:

```php
getMethod($name))) {
// The method does not exist
}
?>
```

...and must be rewritten to use hasMethod():

```php
hasMethod($name)) {
// The method does not exist
}
$m= $class->getMethod($name);
?>
```

If the first version is run, the block below the getMethod() call will never
be reached (as it will throw an exception).

Security considerations
====
n/a

Speed impact
====
None.

Dependencies
====
- BC break - increases minor version (at the time of writing, that would
mean the next release would be 5.7.0)

Related documents
====
- http://xp-framework.net/rfc/contrib/rfc0164.diff
Implementing patch