您可以从构造函数返回 false 吗?
<?php
class ftp_stfp{
//private vars of the class
private $host;
private $username;
private $password;
private $connection_type;
private $connection = false;
function __contruct( $host, $username, $password, $connection_type ){
//setting the classes vars
$this->host = $host;
$this->username = $username;
$this->password = $password;
$this->connection_type = $connection_type;
//now set the connection into this classes connection
$this->connection = $this->connect();
//check the connection was set else return false
if($this->connection === false){
return false;
}
} ... etc etc the rest of the class
调用类:
$ftp_sftp = new ftp_sftp( $host, $uname, $pword, $connection_type );
这实际上是否正确,即 $ftp_sftp var 是否为假或根据 __construct 方法的结果持有该类,或者这是完全错误的逻辑?