PHP's double inclusion prevention code prevents Doxygen from generating documentation

I am writing relatively complex PHP applications and have several class definition files formatted like this:

<?php

if(!class_exists("FooBar"))
{

/**
 * This is documentation for the class FooBar
 */
class FooBar
{
    /**
     * Documentation for FooBar constructor
     */
    public function __construct() {
        ;
    }
}

} // class_exists

      

This is the prevention of multiple definition errors by complex class hierarchies and applications.

However, Doxygen does not document any classes specified this way. Commenting out or removing a statement if(!class_exists())

forces Doxygen to properly document this class, but introduces bugs with applications.

Is there a way to get Doxygen to generate documentation for these classes?

+1


source to share


1 answer


As @Sverri mentioned in the comments, I also believe that autoloading is a good way to solve your problem (which it already did, it seems).

But just for case you (or someone else) are looking for an oxygen-only solution:

You can use INPUT_FILTERS in Doxygen to remove or modify some parts of the source code before generating documentation.

You can use the following php code to remove all lines containing if(!class_exists

, and curly braces {

}

belonging to this if

-block, unless another block follows.

// input
$source = file_get_contents($argv[1]);

// removes the whole line
list($head,$tail) = preg_split('/.*if\(!class_exists\(.+/', $source, 2);   

$openingBracePos = strpos($tail,'{');
$closingBracePos = strrpos($tail,'}');

if($openingBracePos !== false && $closingBracePos !== false)
    $source = $head . substr($tail,$openingBracePos+1,
                             $closingBracePos-$openingBracePos-1);

echo $source;

      

This filter truns



<?php

if(!class_exists("FooBar"))     // This comment will also disappear
{

/**
 * This is documentation for the class FooBar
 */
class FooBar
{
    /**
     * Documentation for FooBar\ constructor
     */
    public function __construct() {
        ;
    }
}

} // class_exists

      

in

<?php



/**
 * This is documentation for the class FooBar
 */
class FooBar
{
    /**
     * Documentation for FooBar constructor
     */
    public function __construct() {
        ;
    }
}

      

Note. On windows, I need to call the filter like this:C:\xampp\php\php.exe php_var_filter.php

You can find some more input filters to improve doxygen php support on GitHub .

+1


source







All Articles