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.

4
  • 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) Commented Aug 14, 2017 at 17:46
  • @albert I've updated the question. Commented Aug 15, 2017 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 stackoverflow.com/questions/4790020/… Commented Aug 15, 2017 at 17:11
  • yes leading backslash means global namespace. but backslash doesn't seem to work at all in @var Commented Aug 15, 2017 at 18:25

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.