1

What does this even do?

/**
 * @return null|string
 */

I'm really confused. I'm applying the leskov substitution principle but does it do anything to a function? or just a note?

Code Lღver
  • 15,573
  • 16
  • 56
  • 75

3 Answers3

3

This is a phpdoc-style documentation comment. It makes generating documentation for reference easier, and most IDEs will pick up on it.

See https://phpdoc.org/docs/latest/getting-started/your-first-set-of-documentation.html

Bytewave
  • 597
  • 1
  • 8
  • 20
  • THANK YOU! Last question, So it's for an IDE then? like for example if I put a @return string the IDE will display a redline if the return type is not string? – Keannu Alforque Atilano Feb 21 '17 at 13:27
  • IDEs may treat it differently, but it's a comment. It doesn't actually matter to the language, it just helps the humans writing it. So, I doubt it would cause any flags in your editor. Or, it would just be a notice. – Bytewave Feb 21 '17 at 13:28
  • In PHP 7, you can specify the return types of a function to the language itself using `method(): returntype {`, but the documentation comment does nothing. – Bytewave Feb 21 '17 at 13:30
  • Thank you so much @Bytewave. – Keannu Alforque Atilano Feb 21 '17 at 13:31
0

It does nothing. /* and */ define a comment block.

Interestingly in PHP, the @ symbol in actual code suppresses any errors that might be caused by that code: see What is the use of the @ symbol in PHP?

But, most likely, the whole thing could be simply some documentation, and the @ used to indicate some documentation metadata.

Community
  • 1
  • 1
Bathsheba
  • 231,907
  • 34
  • 361
  • 483
-1

I believe that's just a comment as that is wrapped in "/**/" tag