Often, I have seen functions being called like
$content = getContent($isAdmin = false)
Whereas the function declaration is like
function getContent($isAdmin = true){
....}
Why would anyone add a overload of creating a variable and using it only once in a function call !!
I understand that this makes the function call clear, but shouldn’t we use PHPDoc blocks instead?
I have the feeling that you are deeply shocked by so much “waste”.
Keep cool, using variables is nothing bad, you should use them often. They normally make your code more descriptive and even faster.
The more descriptive part is the case here, if you look at that line, you see which parameter that is because now it has a name.
Well, actually this is unrelated to (docblock) comments. Even in the function definition, there is no comment for that parameter:
It’s just the definition of the parameter by it’s name. Also the docblock parameter would be only when you define the function:
However that is not where the function is called:
So if you look at that line (and before pressing any hotkey or mouse button), you already read that. Nothing needed, only the code. Works even in notepad or an non-configured gedit.
And btw, if your code needs comments, this is normally a sign that it is too complicated. Also the name of a parameter is much more important than it’s docblock. A good name normally means that you do not need to have a docblock tag for it (that means: less code to maintain), because the name speaks for itself.
Also modern IDEs know the type of the parameter by static analysis and therefore you do not need the docblock tag either. So no, you do not just should always use PHPDocblocks.