0
我有一個名爲Mail中的PHP類和其他類我要做到以下幾點:對象屬性不被識別爲一個數組
if (is_array ($mail->getToAddresses())) {
foreach ($mail->getToAddresses() as $address) {
$mailer->addAddress ($address);
}
}
但如果條件不匹配。它從來沒有進入foreach代碼... 我如何表明該屬性是一個真正的數組? 任何想法?
郵件類:
class Mail {
private $from;
private $fromName;
private $subject;
private $toAddresses;
private $ccAddresses;
private $bccAddresses;
private $message;
public function __construct() {
$this->toAddresses = array();
$this->ccAddresses = array();
$this->bccAddresses = array();
}
public function addToAddress($toAddress) {
$this->toAddresses = $toAddress;
}
public function addCcAddress($ccAddress) {
$this->ccAddresses = $ccAddress;
}
public function addBccAddress($bccAddress) {
$this->bccAddresses = $bccAddress;
}
public function getFrom() {
return $this->from;
}
public function setFrom($from) {
$this->from = $from;
}
public function getFromName() {
return $this->fromName;
}
public function setFromName($fromName) {
$this->fromName = $fromName;
}
public function getSubject() {
return $this->subject;
}
public function setSubject($subject) {
$this->subject = $subject;
}
public function getToAddresses() {
return $this->toAddresses;
}
public function setToAddresses($toAddresses) {
$this->toAddresses = $toAddresses;
}
public function getCcAddresses() {
return $this->ccAddresses;
}
public function setCcAddresses($ccAddresses) {
$this->ccAddresses = $ccAddresses;
}
public function getBccAddresses() {
return $this->bccAddresses;
}
public function setBccAddresses($bccAddresses) {
$this->bccAddresses = $bccAddresses;
}
public function getMessage() {
return $this->message;
}
public function setMessage($message) {
$this->message = $message;
}
public function __toString() {
return "from=" . $this->from . ", fromName=" . $this->fromName . ", subject=" . $this->subject . ", message=" . $this->message;
}
顯示你的對象的實例化完整的代碼,請 –
你確定'$ mail-> getToAddresses()'返回一個數組...只是打印 –
@SherinJose它不打印數組。有任何理想爲什麼? – nmartins