docblox/docblox — Issue #337: Inheritance depends on order of files
Author: hschletz
Created: 2012-01-06 19:05:01+00:00
State: open

Test case: File Class1.php contains a base class like this:

```php
class Class1
{
/**
* Property with docblock
* @var string
*/
protected $_property;
...
}
```

Class2.php contains a derived class that overrides the property, but should inherit the docblock:

```php
class Class2 inherits Class1
{
/** {@inheritdoc} */
protected $_property = 'foo';
...
}
```

Invoking docblox this way will produce the desired result:

docblox Class1.php Class2.php ...

Now reverse the order of files:

docblox Class2.php Class1.php ...

This will produce a literal {@inheritdoc} instead of the parent's documentation.

While maintaining the necessary order when manually providing some files is annoying but possible, things get worse when specifying only a directory where the actual ordering of files is unpredictable. The result may be correct for some files, but not for others.

I tracked down the problem to this part of DocBlox_Plugin_Core_Transformer_Behaviour_Inherit_Node_Class::inherit():

```PHP
if (!isset($this->nodes[$this->getSuperclassName()])) {
$this->reflectExternalClass($this->getSuperclassName());
} else {
$this->inheritClassObject($this->nodes[$this->getSuperclassName()]);
}
```

$this->nodes does not contain the reference to the parent class if the file with the parent class has not been processed yet, in which case inheritClassObject() is not called.