make参数默认值为CONSTANT = PHP中的字符串

时间:2013-06-06 17:30:52

标签: php

我试图创建一个函数参数的默认值,作为一个常量与字符串连接的组合,但似乎我不能在那里进行连接操作。

public function __construct($test = __DIR__."/mypath") { ...

当然,我可以做这个>

public function __construct($test = null) {
    if($test === null) {
        $test = __DIR__."/mypath"
    }

BUt我想知道是否有更清洁的方式。有吗?

1 个答案:

答案 0 :(得分:2)

创建一个类变量,然后重新赋予它构造

var $path = __DIR__."/mypath"; // Really better off to be an absolute path

public function __construct($test = null) {
    if($test !== null) {
        $this->path = $test;
}
相关问题