A DocBlock is a specially formatted PHP comment which allows external document generators to generate documentation of APIs and helps some IDEs to interpret variable types, provide improved code completion, type hinting and debugging.
Questions tagged [docblocks]
104 questions
2
votes
1 answer
Mocking docblock annotations in PHPUnit
I am building an app that implements custom docblock annotations using the Doctrine Annotations library.
For PHPUnit testing, is it possible to create a mocked class that has mock docblocks?
From this answer, I learned how to mock a class, like…

Kerry Randolph
- 591
- 6
- 15
2
votes
1 answer
In DocBlocks, should I always use a single line notation when writing one line?
Let's say I have one line of summary, must I right it like that:
/** summary */
or can I write it like this:
/**
* summary
*/
I prefer the second option, but is that required to use the first option?

Michael Haddad
- 4,085
- 7
- 42
- 82
2
votes
1 answer
PHPDocumentor - what's wrong with my DocBlock?
I'm putting in some comments in some legacy code, and I've run across a small issue with PHPDocumentor.
Here's an example:
/**
* Constructs the Widget object
*
* Basic constructor for the widget object.
* Another line of pointless explanation,…

Dycey
- 4,767
- 5
- 47
- 86
2
votes
1 answer
How to document PHP @return when you are returning view in MVC
So let's say that in my controller inside some of my methods I want to return a view like this:
return $this->render('home', [
'model' => $model,
]);
In my doc block, I want to document what this method is returning. I do not know how to…

offline
- 1,589
- 1
- 21
- 42
1
vote
2 answers
How can I use docblock hints with classes for $this variables?
I'm using NetBeans as my IDE. Whenever I have some code that uses another function (usually a factory) to return an object, typically I can do the following to help with hinting:
/* @var $object FooClass */
$object =…

Nick
- 2,872
- 3
- 34
- 43
1
vote
0 answers
php laravel IDE typehint magic methods (scope/attribute)
Using laravels magic with scopes I can typehint the scope name as it is used in the code (hasName). However it will then not be picked up by the IDE, if the scopeHasName is being used and where it is used. Is there some way to "alias" those two.…

Chris
- 13,100
- 23
- 79
- 162
1
vote
0 answers
VS Code Show Where Potential Unhandled Exceptions Could Be Thrown
In VS Code, doc block info can be automatically generated that looks something like this:
/**
* Some sample function.
* @param Request $request
* @return JsonResponse
* @throws BadRequestException
* @throws BindingResolutionException
…

Josh
- 714
- 2
- 8
- 20
1
vote
0 answers
PHPDocumentor, phpdoc - missing file-level and global variable comments; 'alse' and 'rue'
I am a newbie to phpDocumentor, although I have extensively used JavaDoc in the past.
To start, I created the following test file a.php:

Leszek Pachura
- 403
- 4
- 18
1
vote
1 answer
PhpStorm inspection errors for thrown exception
I am trying to catch a custom exception, but keep getting an Exception 'CustomException' is never thrown in the corresponding try block inspection error for the following scenario:
class CustomException extends Exception { }
class Test {
/**
…

MultiDev
- 10,389
- 24
- 81
- 148
1
vote
1 answer
In Php, how do I set the return type of a variable using inline type hinting
How can I avoid this "error":
Basically docblocks for DataObject::get_one says that it returns a DataObject, which is true, but most of the time it is a class that extends DataObject - e.g. class HealthCheck extends DataObject in this case.
If I…

Nicolaas Thiemen Francken
- 311
- 2
- 11
1
vote
1 answer
How to use a $this reference inside PHP docblocks
I have a project that utilised MVC where the view file is inherting $this which refers to a view class attached to the controller.
Helper classes have been attached in some of the views and are used like…

bcmcfc
- 25,966
- 29
- 109
- 181
1
vote
1 answer
I need to use a splat operator within a PHP docblock and cannot figure out how to escape the character
I am using codeception and running multiple sets of example data.
I am sending in multiple accept headers, one of which is "*/*".
so the example code is:
/**
* My description of the test
*
* GET a/path/i/am/testing
*
*…

so_blue
- 41
- 1
- 4
1
vote
1 answer
How to set the @return value of a dynamic function?
Say I have this function:
function load_model($modelName)
{
$model = new $modelName;
return $model;
}
Using it, I can do:
$userModel = load_model('user');
$forumModel = load_model('forum');
etc. Both will be different models with different…

Ali
- 261,656
- 265
- 575
- 769
1
vote
1 answer
Missing file from documentation generated with phpDocumentor: No summary was found for this file on line 0
The documentation for all other files are being generated, but for src/Pagination/Paginator.php, it isn't. This is a Symfony 4 application.
The related error is:
error: Line 0: No summary was found for this file
No summary? That's wrong. The file…

alqm
- 75
- 4
1
vote
1 answer
Override PHP docblock/annotation of method without overloading (PhpStorm autocompletion)
This is a question about the autocompletion behavior in PhpStorm (and possibly other IDEs) in conjunction with PHP docblocks.
I have to groups of classes in my application. First there are individual classes for various products (CarProduct,…
user7394454