How to document a parameter that expects a constant

What is the recommended way to document the parameters of a function or method whose value should be a predefined constant? For now, I'm using a constant data type, and I'll add a little explanation later.

eg:.

<?php class Foo{ const METHOD_GET = 'get'; const METHOD_POST = 'post'; /** * Load a new foo * * @param string $method HTTP method to use (either Foo::METHOD_GET or Foo::METHOD_POST) */ public function load($method=Foo::METHOD_POST){ // ... } /** * Sort current foo * * @param int $sort_order Sort order (either SORT_ASC or SORT_DESC) */ public function sort($sort_order=SORT_ASC){ // ... } } 
+7
source share
2 answers

Given that you can use a known class like dataype in the param and return tags, I would also expect that you can use a known constant. If you want to specify several type parameters, simply split the list into pipes. Change your example:

 /** * Load a new foo * * @param Foo::METHOD_GET|Foo::METHOD_POST $method HTTP method to use */ public function load($method=Foo::METHOD_POST){ // ... } 

Since the data type in this case is a known value inside the class, it can work even without the class prefix:

 * @param METHOD_GET|METHOD_POST $method HTTP method to use 
+5
source

Here is information on how to document a constant using phpdoc

const / define means the same thing in php

-2
source

All Articles