php - Is there a way to specify a mandatory array key/index via PHPDoc?
855
If a function requires an incoming array to have a specific key/index, is there an eloquent way to express it via comments, specifically PHPDoc?
For example:
/**
* Just an example function
* @param array $arr My Example Array
*/
public function myFunction( $arr ){
if(!array_key_exists('mykey', $arr)){
echo 'Damnit, we needed an array that had mykey as an index!';
}
}
Answer
Solution:
You could write a list of such keys, and place it in the @param description, or put it in the long description of the method's docblock. There is nothing "automated" or "rigid" that phpDocumentor could really do in the documentation here, e.g. link to some other documented element.
Answer
Solution:
No, if you need a specific variable, make it a separate parameter. In that case, if the parameter is empty, an error is thrown.
You can't specify the data-type of array values in PHP. So there is noeed to document that via PHPDoc.
Answer
Solution:
NO there is not. Best to just put it in the comments section.