문제

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])

다른 팁

You can use reflection class for this too.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top