How to implement php constructor that can accept different number of parameters?
Like
class Person {
function __construct() {
// some fancy implementation
}
}
$a = new Person('John');
$b = new Person('Jane', 'Doe');
$c = new Person('John', 'Doe', '25');
What is the best way to implement this in php?
Thanks,
Milo
One solution is to use defaults:
The second one is to accept array, associative array or object (example about associative array):
But in the second case it should be passed like this:
The third option has been pointed by tandu:
EDIT: Pasted here what I was able to retrieve from original answer by tandu (now: Explosion Pills).