thekid/rfc — Issue #185: RFC 0185: ClassFormatException for malformed annotations
Author: thekid
Created: 2011-10-09 15:39:50+00:00
State: open

Scope of Change
====
Malformed annotations will lead to a `lang.ClassFormatException`
being thrown instead of `XPClass::(has|get)Annotation[s]` silently
returning FALSE.

Rationale
====
It is not easy to detect a malformed annotation in a production environment.
The only sign is a `"[error] PHP Parse error: syntax error, unexpected
',', expecting ')' in lang/XPClass.class.php(503) : eval()'d code on line 1
"` that will appear on the screen / in a logfile.

Functionality
====
Annotations are parsed from the class' sourcecode at runtime and then
converted to PHP values by using `eval()`. This is where the parse
error mentioned above comes from.

The error can be caught by a userland implementation:

```
$ php -r 'var_dump(eval("return (")); echo "Alive";'

Parse error: parse error in Command line code(1) : eval()'d code on line 1
bool(false)
Alive

```

To capture the message, we can use output buffering - `ob_start()` and
`ob_get_contents()`.

Security considerations
====
n/a

Speed impact
====
n/a

Dependencies
====
n/a

Related documents
====
* http://xp-framework.net/rfc/contrib/rfc0185.diff
Implemeting patch

Comments
====
friebe, Tue Apr 28 12:47:57 2009
----
This will be implemented in 5.8.0 because of the impact on core
functionality.

friebe, Tue Aug 25 10:06:37 2009
----
Implemented in 5_8 branch