Esempio:standard phpdoc per l'impostazione del valore predefinito di un parametro opzionale?
/**
* This function will determine whether or not one string starts with another string.
* @param string $haystack <p>The string that needs to be checked.</p>
* @param string $needle <p>The string that is being checked for.</p>
* @param boolean $case[optional] <p>Set to false to ignore case(capital or normal characters)</p>
* @return boolean <p>If the $haystack string does start with the $needle string, the return will be true. False if not.</p>
*/
function endsWith($haystack,$needle,$case=true) {
if($case){return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)),$needle)===0);}
return (strcasecmp(substr($haystack, strlen($haystack) - strlen($needle)),$needle)===0);
}
Il parametro opzionale è impostato su true
per impostazione predefinita. Desidero indicare quale è l'impostazione predefinita nella documentazione. C'è un modo standard per farlo o devo menzionarlo nella descrizione?
Grazie. E mi fa sentire un po 'meglio, sì :) – KdgDev
Questa è la risposta nel caso in cui un parametro opzionale è incluso nella firma della funzione. Ma cosa succede se non lo è? Come documentare un parametro opzionale? Come da documenti, l'unico modo è dirlo nella descrizione. Quindi non c'è modo di scrivere per esempio '[$ case = true]'. Anche jsdoc ce l'ha. – FreeLightman