Item within comment in PHP

Asked

Viewed 220 times

0

Captura de tela

If the "@Return string" inside the encoding of a PHP file is deleted, will the encoding suffer significant changes? I can delete all comments including "@Return string"?

And lastly, why did he turn a different color?

  • In this case no. this is just a comment that means the return type of the method errorMessage. You can erase everything inside the /** until */ the code will continue working. The color depends a lot on the theme of your editor has no way to answer this without knowing the theme!

2 answers

2

No, the @return string is only documentation of the method, in format Docblock. Your IDE and other tools, for example, the Phpdoc, use these special comments to give you information of what the code does.

In this case, the @return is indicating what type of value the function returns, which is string.

You can delete the entire comment, but I recommend you use this feature to comment on your personal code.

The different color is the IDE that understands Phpdoc and "paints" differently to indicate that it is something "special".

When you are writing a call to that function, the IDE will display a tooltip that will use those comments to let you know how to use it.

  • Thank you, Leite! ;)

1


All content within /* */ is a comment and all comments will be ignored when running the application, that is, they will never interfere with the end result of any application

So yes you can delete, but it is not recommended, on the contrary, it is better to insert it everywhere else, it explains the functioning, in case, what the function should return

Comments that start with /** means that they are documentation comments, many Ides use this data that are in these comments to give more information of the function:

inserir a descrição da imagem aqui

In the example some information of the parameter is shown path of function readFile Javascript (Node.js), also note that although javascript is weakly typed, that is, the types of variables are not defined, the description of the function has the information that path must be a string, number, buffer or url. This is very common in weakly typed languages, for example, so that one knows what must be passed in that function parameter

In addition to setting what should be passed by the parameter and the return can be set the author, version, if it is obsolete, comment on the constructor and destructor (in the case of the class)

The different color is because your IDE recognized that this was a feature documentation comment

  • I understand perfectly, William. Thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.