Skip to content
Advertisement

phpDocumentor – Do comment references to other elements need a fully qualified path?

I couldn’t really interpret a clear answer about this from the documentation.

When adding a reference to another structural element in a @see or @param comment, for example, do I always need to use the fully qualified name of the element, even if the two elements are local to each other?

e.g. Object hierarchy

Animals
    --- Mammals
        --- Cat
        --- Dog

Let’s say within the Cat class I want to reference Dog. As they reside within the same namespace, do I need to give the fully qualified path? If it doesn’t matter either way, is there a best practice? Should I use the fully qualified path anyway, to remove any ambiguity or misunderstanding by developers reading the code?

namespace AnimalsMammals;

class Cat
{

    /**
     * @param Dog $dog An instance of a Dog.
     *
     * OR
     *
     * @param AnimalsMammalsDog $dog An instance of a Dog.
     */
    public function foo(Dog $dog)
    {
        // ...
    }
}

Advertisement

Answer

No, it isn’t necessary.

Definition of a ‘Type’

A valid class name seen from the context where this type is mentioned. Thus this may be either a Fully Qualified Class Name (FQCN) or if present in a namespace a local name.

phpDocumentor only needs that class type should be documented:

@param

If the return Type is a class that is documented by phpDocumentor, then a link to that class’ documentation is provided.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement