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

899 questions
455
votes
15 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
  • 21,516
  • 18
  • 92
  • 115
159
votes
4 answers

PHP function comments

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 IDE gives me a dropdown…
Zim
  • 5,403
  • 7
  • 27
  • 19
99
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
  • 52,335
  • 19
  • 158
  • 208
91
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
  • 27,240
  • 15
  • 95
  • 114
91
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,484
  • 9
  • 40
  • 48
87
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
  • 2,228
  • 3
  • 19
  • 18
53
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
  • 2,031
  • 5
  • 23
  • 34
46
votes
3 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
  • 811
  • 1
  • 8
  • 6
43
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
  • 50,745
  • 59
  • 165
  • 240
42
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
  • 36,084
  • 8
  • 78
  • 90
40
votes
5 answers

How can I use PHPDoc to type-hint the parameters of a Callable?

I have a method that accepts a callback as a parameter. I would like to provide a signature in the PHPDoc for the class method that outlines the parameters for the callback function to be passed to that method so that my IDE (PHPStorm) can produce…
ringmaster
  • 2,879
  • 3
  • 28
  • 31
39
votes
3 answers

PHPStorm: correct PHPDoc for a Collection of Objects?

I'm using the PHPStorm IDE, and run into trouble when I run the code inspection. I have a method which returns a collection of objects. The Collection itself is an object, which has its own methods, and implements the Traversable interface: class…
BenMorel
  • 34,448
  • 50
  • 182
  • 322
36
votes
4 answers

Comment associative array in PHP Documentor

I use several associative arrays in my PHP application and I'm using PHP documentor to comment my sources. I never really did specify comments for the arrays in an array, but now I need to do that and don't know how. $array = array('id' => 'test',…
Abenil
  • 1,048
  • 3
  • 12
  • 26
36
votes
4 answers

How to document class properties in PHP 5 with phpDocumentor

Take in consideration the following PHP 5 class: class SomeClass { //I want to document this property... private $foo; function __construct() { } public function SetFoo($value) { $this->foo = $value; } …
AlexV
  • 22,658
  • 18
  • 85
  • 122
36
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,993
  • 9
  • 57
  • 88
1
2 3
59 60