我知道 OOPS 中的以下类型的构造函数:
- 参数化
- 默认
- 复制
但我不确定 php 是否支持所有这些。 php支持哪些类型的构造函数
最佳答案
PHP 支持所有这些:
class A {
// default is a build-in non-parametrized one
public function __construct(/* arguments */){
// parametrized
}
public function __clone(){
// copy
}
}
// if __construct() is not declared, then uses default one:
$a = new A;
// if __construct() is declared, then uses parametrized one:
$a = new A(/* arguments */);
// if __clone() is declared, then uses copy one:
$b = clone $a;
引用文献:
关于php - php中有多少种构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19076291/