1

I'm starting to use Doxygen to document my PHP code. See following example:

namespace \MyClasses;

class Order {
    /**
     * Some Description
     *
     * @var \MyClasses\Customer $customer
     */
    protected $customer;
}

The @var command renders to MyClasses Customer MyClasses\Order::$customer as type instead of \MyClasses\Customer MyClasses\Order::$customer which would be correct, leaving the namespace intact. Is there any way to achieve this? Putting two backslashes \\MyClasses\\Customerdoesn't work either.

@param on the other hand seems to work with namespaces.

I'm using the latest version 1.8.13. Config is almost default.

musicman
  • 504
  • 6
  • 16
  • Please state doxygen version as well as a, more, complete example (source and changes in configuration file compare to the default Doxyfile) as it is unclear what \BaseClass might be (especially for people with non or little PHP knowledge) – albert Aug 14 '17 at 17:46
  • @albert I've updated the question. – musicman Aug 15 '17 at 15:40
  • I don't think doxygen is supporting this at the moment. Did some googling for the meaning of the initial backslash and found https://stackoverflow.com/questions/4790020/what-does-a-backslash-do-in-php-5-3 – albert Aug 15 '17 at 17:11
  • yes leading backslash means global namespace. but backslash doesn't seem to work at all in @var – musicman Aug 15 '17 at 18:25

1 Answers1

1

If anyone still comes across this question, it was 'resolved' on doxygen's support. Here's the Bugzilla bug_795953 (now at: https://github.com/doxygen/doxygen/issues/5553).

All you have to do (in a PHP file) is create/customize a INPUT_FILTER for doxygen and include this piece of code:

<?php
// Input
$source = file_get_contents($argv[1]);
// removes preceding '\' or '::' for the use of namespaces.
$regexp = '/ \\\\/';
$replace = ' ';
$source = preg_replace($regexp, $replace, $source);
// adds possibility to use '\' for namespaces
$regexp = '/\\\\/';
$replace = '::';
$source = preg_replace($regexp, $replace, $source);
// Output
echo $source;
?>

This works if you use all your documenting 'commands' starting with an '@' (@var, @param, etc). If you don't, you have to do some tweaking on the regexp and make it work like this, too.

The reason why doxygen doesn't identify the namespace is because the '\' key is set as a doxygen's command, so it can't be used for anything else in the code. So changing all the '\' to '::', will make it understand that that's a namespace reference.

albert
  • 8,285
  • 3
  • 19
  • 32