I've got this constructor that takes an optional argument. The main problem with this is usability. The developer using my framework will catch a headache instantly because he doesn't know if he can provide an argument, what kind of argument, or if he can't at all. Conclusion: It just sucks. But PHPDoc may help a little bit if someone has a reasonable IDE like Netbeans installed ;)
So:
class ChildClass extends ParentClass {
public function __construct() {
$tplFile = func_get_arg(0);
if (!isset($tpl)) {
$tpl = 'index';
}
parent::__construct($tpl);
}
}
How could I use PHPDoc here to indicate that there can be provided an optional [$tpl] argument?
Declare a parameter and give it a preset:
public function __construct($my_argument = 0)
my IDE (phpEd, which is phpDoc sensitive) interprets it correctly. phpDoc should, too, and put the parameter into braces:
show ([$my_argument])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With