What does @param mean in a class? What does @param mean in a class? php php

What does @param mean in a class?


@param doesn't have special meaning in PHP, it's typically used within a comment to write up documentation. The example you've provided shows just that.

If you use a documentation tool, it will scour the code for @param, @summary, and other similar values (depending on the sophistication of the tool) to automatically generate well formatted documentation for the code.


As others have mentioned the @param you are referring to is part of a comment and not syntactically significant. It is simply there to provide hints to a documentation generator. You can find more information on the supported directives and syntax by looking at the PHPDoc project.

Speaking to the second part of your question... As far as I know, there is not a way to specify the return type in PHP. You also can't force the parameters to be of a specific primitive type (string, integer, etc).

You can, however, required that the parameters be either an array, an object, or a specific type of object as of PHP 5.1 or so.

function importArray(array $myArray){}

PHP will throw an error if you try and call this method with anything besides an array.

class MyClass{}function doStuff(MyClass $o){}

If you attempt to call doStuff with an object of any type except MyClass, PHP will again throw an error.


I know this is old but just for reference, the answer to the second part of the question is now, PHP7.

// this function accepts and returns an int function age(int $age): int{  return 18;}