例如在C#中你可以使用相同的方法名重载方法但是PHP呢?
class Database {
private $dsn;
private $host;
private $user;
private $password;
private $enckey;
function __construct($dbname, $host, $user, $password) {
$this->dsn = "mysql:dbname=" . $dbname . ';host=' . $host;
$this->user = $user;
$this->password = $password;
}
function __construct($dbname, $host, $user, $password, $enckey) {
$this->dsn = "mysql:dbname=" . $dbname . ';host=' . $host;
$this->user = $user;
$this->password = $password;
$this->enckey = $enckey;
}
}
答案 0 :(得分:7)
有什么意义?
class Database {
private $dsn;
private $host;
private $user;
private $password;
private $enckey;
function __construct($dbname, $host, $user, $password, $enckey = null) {
$this->dsn = "mysql:dbname=" . $dbname . ';host=' . $host;
$this->user = $user;
$this->password = $password;
$this->enckey = $enckey;
}
}