小编mar*_*984的帖子

我的可选PHP参数出错了什么?

我有以下课程:

class MyClass {

    public function __construct($id = 0, $humanIdentifier = '') {
        $this->id = $id;
        $this->humanID = $humanIdentifier;
    }
}
Run Code Online (Sandbox Code Playgroud)

所以根据我的解释,我应该能够将$ id或$ humanIdentifier传递给该构造函数,如果我想要的话,都不能或两者都传递.但是,当我调用下面的代码时,我发现构造函数args中的$ id被设置为hello world而不是$ humanIdentifier,尽管我在调用构造函数时指定了$ humanIdentifier.任何人都可以看到我错在哪里?

$o = new MyClass($humanIdentifier='hello world');
Run Code Online (Sandbox Code Playgroud)

php constructor class

1
推荐指数
1
解决办法
75
查看次数

标签 统计

class ×1

constructor ×1

php ×1