标签:private 适配器 return public function
class errorObject {
public $error;
public function __construct ($error){
$this->error = $error;
}
public function getError (){
return $this->error;
}
}
class logToConsole {
private $_errorObject;
public function __construct($_errorObject){
$this->_errorObject = $_errorObject;
}
public function write(){
$fileName = "D:/wamp/www/tc/tc.txt";
$f=fopen($fileName, "a+");
@fwrite($f, $this->_errorObject->getError());
}
}
class logToCsv {
private $_errorObject;
public function __construct ($errorObject){
$this->_errorObject = $errorObject;
}
public function write(){
$line = $this->_errorObject->getNumber();
$line .= ‘,‘;
$line .= $this->_errorObject->getStr();
$line .= ‘\n‘;
fwrite($handle, $line);
}
}
class logToCsvAddpter extends errorObject{
private $_errorNumber;
private $_errortext;
public function __construct($error){
parent::__construct($error);
$part = explode(‘:‘, $this->getError());
$this->_errorNumber = $part[0];
$this->_errortext = $part[1];
$this->_errorObject = $errorObject;
}
public function getNumber(){
return $this->_errorNumber;
}
public function gettext(){
return $this->_errortext;
}
}
$error = new logToCsvAddpter("aaaaaaa");
$log = new logToCsv($error);
$log->write();
本文出自 “php学习” 博客,谢绝转载!
标签:private 适配器 return public function
原文地址:http://xiaochaozi.blog.51cto.com/6469085/1531684