addendum
addendum copied to clipboard
Addendum::getDeclaredAnnotations() caches declared classes > Problem
The static method getDeclaredAnnotations on class Addendum caches all the
declared classes in Addendum::$annotations.
When you try something like this:
File: AnimalAnnotation.php:
<?php
class Animal extends Annotation {}
?>
File: HumanAnnotation.php:
<?php
class Human extends Annotation {}
?>
File: Parser.php
<?php
include("addendum.php");
// Include the Animal Annotation:
include("AnimalAnnotation.php");
// Do not include the HumanAnnotation yet
/** @Animal */
class Dog {
// some code
}
$reflection = new ReflectionAnnotatedClass('Dog');
// $reflection now contains the annotations of class Dog
// Now include the HumanAnnotation
include("HumanAnnotation.php");
/** @Human */
class Ruud {
// some code
}
$reflection = new ReflectionAnnotatedClass('Ruud');
?>
Now you get this exception: "Unknown class passed as parameter"
This is logical because the first time Addendum::getDeclaredAnnotations()
is called (by Addendum::resolveClassName()) it will cache all declared
classes using get_declared_classes().
When you declare new annotations by including the files (like
HumanAnnotation.php) they won't show up in the cached annotations.
A quick fix I made is the following function for the Addendum class:
<?php
public static function resetDeclaredAnnotations() {
self::$annotations = false;
}
?>
Now I can call Addendum::resetDeclaredAnnotations() after I load new
annotations.
Original issue reported on code.google.com by [email protected] on 2 Feb 2010 at 12:03