Andrewsville/PHP-Token-Reflection — Issue #28: Alternative class property definition error
Author: runfalk
Created: 2011-12-01 18:31:02+00:00
State: open

I use an alternative way of declaring and documenting object properties. This is a short example illustrating what I'm doing. PHP's internal reflection support this while PHP-Token-Reflection does does not.

```php
getProperties() as $p) {
var_dump(array(
"name" => $p->getName(),
"doc" => $p->getDocComment(),
"modifiers" => Reflection::getModifierNames(
$p->getModifiers())));
}
```

The output of this is:

```
runfalk@dev:~$ php -v
PHP 5.3.3-7+squeeze3 with Suhosin-Patch (cli) (built: Jun 28 2011 13:13:26)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans
with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH
runfalk@dev:~$ php test.php
array(3) {
["name"]=>
string(6) "length"
["doc"]=>
string(27) "/** Holds current length */"
["modifiers"]=>
array(1) {
[0]=>
string(6) "public"
}
}
array(3) {
["name"]=>
string(5) "index"
["doc"]=>
string(30) "/** Remembers current index */"
["modifiers"]=>
array(1) {
[0]=>
string(6) "public"
}
}
```

If the file above is saved as *test.php*:

```php
processFile("test.php");
```

This yeilds:

```
PHP Fatal error: Uncaught exception 'TokenReflection\Exception\Parse' with message 'The property name could not be determined.' in /usr/share/php/TokenReflection/ReflectionProperty.php:505
Stack trace:
#0 /usr/share/php/TokenReflection/ReflectionProperty.php(427): TokenReflection\ReflectionProperty->parseName(Object(TokenReflection\Stream\FileStream))
#1 /usr/share/php/TokenReflection/ReflectionBase.php(141): TokenReflection\ReflectionProperty->parse(Object(TokenReflection\Stream\FileStream), Object(TokenReflection\ReflectionClass))
#2 /usr/share/php/TokenReflection/ReflectionClass.php(1838): TokenReflection\ReflectionBase->__construct(Object(TokenReflection\Stream\FileStream), Object(TokenReflection\Broker), Object(TokenReflection\ReflectionClass))
#3 /usr/share/php/TokenReflection/ReflectionBase.php(154): TokenReflection\ReflectionClass->parseChildren(Object(TokenReflection\Stream\FileStream), Object(TokenReflection\ReflectionFileNamespace))
#4 /usr/share/php/TokenReflection/ReflectionFileNamespace.php(275): TokenReflection in /usr/share/php/TokenReflection/Broker.php on line 220
```

As this is perfectly valid code, as well as supported by PHP's internal reflection, I consider this a bug.