Questions tagged [phpdoc]

phpDocumentor (phpdoc) is an automatic code-documentation tool for PHP, based on Javadoc.

Run from either the command-line or a web interface, phpDocumentor is a tool written in PHP used to generate documentation directly from the source code of a PHP project.

Features include:

  • Linking between documentation
  • Automatic class inheritence
  • Highlighted source code with cross-references to general PHP documentation

Popular questions

857 questions
428
votes
13 answers

PHPDoc type hinting for array of objects?

So, in PHPDoc one can specify @var above the member variable declaration to hint at its type. Then an IDE, for ex. PHPEd, will know what type of object it's working with and will be able to provide a code insight for that variable.
Artem Russakovskii
  • 20,170
  • 17
  • 87
  • 114
130
votes
4 answers

PHP Function Comments

Just a quick question: I've seen that some PHP functions are commented at the top, using a format that is unknown to me: /** * * Convert an object to an array * * @param object $object The object to convert * @return array * */ My…
Zim
  • 4,971
  • 7
  • 23
  • 19
88
votes
6 answers

Variable type hinting in Netbeans (PHP)

Just curious if there's a way in netbeans to give type hints for regular variables, so that intellisense picks it up. I know you can do it for class properties, function parameters, return types, etc. but I can't figure out how to do it for regular…
rr.
  • 6,114
  • 8
  • 37
  • 43
81
votes
6 answers

PHPDoc: @return void necessary?

Is it really necessary do something like this: /** * ... * * @return void */ I have quite a few methods that don't have a return value, and it seems really redundant to put something like this in the comment. Would it be considered bad form to…
Richie Marquez
  • 1,989
  • 3
  • 17
  • 18
80
votes
6 answers

What is the correct way to write PHPDocs for constants?

I have this code: /** * Days to parse * @var int */ const DAYS_TO_PARSE = 10; ... I don't think that using @var is correct for a constant and I don't see any @constant PHPDoc tag. What is the correct way to do this?
Elzo Valugi
  • 24,234
  • 13
  • 88
  • 112
69
votes
9 answers

Best way to document Array options in PHPDoc?

I'm struggling to write readable and easy to understand documentation that describes the multi-tree structure for Array options that are passed to a function. Here is an example array structure. $arr = [ 'fields' => [ 'title' => [ …
Reactgular
  • 43,331
  • 14
  • 114
  • 176
49
votes
4 answers

Should I use @return self, this or the current class?

I have a method that return the current object, how do I document this? /** * set something * * @return this */ public function setSomething(){ // ... return $this; } Or should I do @return self or @return…
lucaswxp
  • 1,464
  • 4
  • 15
  • 27
36
votes
2 answers

Best way to document (phpdoc) generators (methods that yield)

What is the best way to document, for phpdocumentor2, a method that is a generator. I don't think @return really works for yield, but I can't seem to find any proper alternative. Is it just a matter of waiting for phpdoc to catch up?
Mat-Locomotive
  • 661
  • 7
  • 6
34
votes
2 answers

Can you hint an array's items type?

This question is linked to this one : Is it possible to hint the type of the items inside a returned array ? e.g. : /** * MyFunction does a lot of things * * @param TClass1 $var1 * @param TClass2 $var2 * @return array[TClass3] //<- I'm trying…
LeGEC
  • 29,595
  • 2
  • 37
  • 78
34
votes
2 answers

Correct syntax for inheritDoc in phpDocumentor

What is the correct syntax for @inheritDoc in phpDocumentor if I just want to inherit all of the documentation from parent? Maybe more than one syntax is correct? @inheritDoc {@inheritDoc} @inheritdoc {@inheritdoc} The documentation is pretty…
Borek Bernard
  • 43,410
  • 50
  • 148
  • 224
34
votes
4 answers

Best practices: Use of @throws in php-doc, and how it could be handle

Let's say I have a class with a method like this: /* * * Loads the user from username. * * @param string $username The username * * @return UserInterface * * @throws userNotFoundException if the user is not found */ public function…
Federkun
  • 30,933
  • 8
  • 62
  • 80
33
votes
2 answers

Sublime Text 2 Comment/Doc Block

Recently, I decided to try out Sublime Text 2 as a TextMate alternative (which it is). I'm absolutely loving it but the only issue that bugs me is that it doesn't continue the PHP Comment/Doc Block upon pressing "Enter". It just adds new blank lines…
Taha
  • 381
  • 1
  • 5
  • 12
33
votes
2 answers

annotating a local variable in php

I am using Eclipse PDT and I want to annotate a local variable using Phpdoc. All I see is that I can annotate the variables/properties of a class using @var or even @property, but how is this possible for a local variable? How can I do something…
tzortzik
  • 4,401
  • 9
  • 43
  • 74
33
votes
1 answer

PHPDoc optional parameter

There are already 2 similar questions of this type here on SO but none of the answers seem to work. PHPDoc doesn't seem to recognize optional parameters in my functions as optional, for example: /** * Opens the connection and sets encoding * *…
user2742648
32
votes
1 answer

What is the correct way to display a multi-line @param using PHPDoc?

From what I've done research on, I can't seem to find a correct method to format a multiline phpdoc @param line. What is the recommended way to do so? Here's an example: /** * Prints 'Hello World'. * * Prints out 'Hello World' directly to the…
Sean
  • 2,173
  • 21
  • 42
1
2 3
57 58