Re: [請益] 請問一下這個operator是什麼?

作者: tanson (Flash)   2014-07-16 13:01:53
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;
: : "->"
: : 請問大大們,這個是什麼運算子啊?

Links booklink

Contact Us: admin [ a t ] ucptt.com