Bug #47114

@var annotations with included variable throw exception

Added by Alexander Berl over 8 years ago. Updated over 7 years ago.

Status:
Resolved
Priority:
Should have
Category:
Property
Target version:
-
Start date:
2013-04-10
Due date:
% Done:

100%

Estimated time:
PHP Version:
Has patch:
No
Complexity:
easy

Description

Currently all @var annotations which contain whitespaces are regarded as illformed and throw a InvalidPropertyTypeException.
However, it is common - at least for 3rd party code - to write @var annotations that look as follows:

/**
 * @var integer $number
 */
protected $number;

A good example for this are the gedmo doctrine extensions.

Hence I suggest to parse out all variable references in the annotation before deciding on being illformed.

See ReflectionService@1231:

$declaredType = trim(implode(' ', $this->getPropertyTagValues($className, $propertyName, 'var')), ' \\');

instead:
const VARIABLE_NAME_REGEX = '/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/';
...
$declaredType = implode(' ', $this->getPropertyTagValues($className, $propertyName, 'var'));
$declaredType = trim(preg_replace(self::VARIABLE_NAME_REGEX, '', $declaredType), ' \\');

Also available in: Atom PDF