Re: [請益] 請問一下這個operator是什麼?
1. 一般屬性設定方法
class mail
{
protected $_transport;
public function setTransport($transport)
{
$this->_transport = $transport;
}
public function getTransport()
{
return $this->_transport;
}
}
$mail = new Mail();
$mail->setTransport('smpt');
echo $mail->getTransport(); // print 'smtp'
$mail2 = new Mail();
$mail->setTransport('sendMail');
echo $mail->getTransport(); // print 'sendMail'
2. 靜態屬性設定方式
class mail
{
static protected $_transport;
static public function setTransport($transport)
{
self::$_transport = $transport;
}
static public function getTransport()
{
return self::$_transport;
}
}
$mail = new Mail();
$mail2 = new Mail();
mail::setTransport('smtp');
echo $mail::getTransport(); // print 'smtp'
echo $mail2::getTransport(); // print 'smtp'
mail::getTransport(); // print 'smtp'
一般使用-> 設定屬性或使用方法,屬性值存在該類別內
靜態使用:: 設定靜態的屬性或方法,
屬性值可以想像是該類別的全域變數,只會有一個值
※ 引述《wanzoo (Zoo)》之銘言:
: 可否請大大們示範一下用法?
: 網路上找得到的資料都有點模糊。
: 另外還有一個「::」,也是同樣的東西嗎?
: ※ 引述《wanzoo (Zoo)》之銘言:
: : if(!$this->PreSend()) return false;
: : return $this->PostSend();
: : } catch (phpmailerException $e) {
: : $this->mailHeader = '';
: : $this->SetError($e->getMessage());
: : if ($this->exceptions) {
: : throw $e;
: : }
: : return false;
: : "->"
: : 請問大大們,這個是什麼運算子啊?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 210.242.161.16
※ 文章網址: http://www.ptt.cc/bbs/PHP/M.1405486916.A.202.html
※ 編輯: tanson (210.242.161.16), 07/16/2014 13:03:04
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):