【发布时间】:2011-05-13 01:01:54
【问题描述】:
如何实现可以接受不同数量参数的php构造函数?
喜欢
class Person {
function __construct() {
// some fancy implementation
}
}
$a = new Person('John');
$b = new Person('Jane', 'Doe');
$c = new Person('John', 'Doe', '25');
在 php 中实现此功能的最佳方法是什么?
谢谢, 米洛
【问题讨论】:
-
构造函数参数的工作方式与任何其他函数的参数一样。只需指定默认值 php.net/manual/en/… 或使用
func_get_args() -
构造函数参数的工作方式与任何其他函数的参数一样。只需指定默认值 php.net/manual/en/... 或使用 func_get_args()
标签: php constructor multiple-constructors