作者tanson (Flash)
看板PHP
标题Re: [请益] 请问一下这个operator是什麽?
时间Wed Jul 16 13:01:53 2014
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://webptt.com/cn.aspx?n=bbs/PHP/M.1405486916.A.202.html
※ 编辑: tanson (210.242.161.16), 07/16/2014 13:03:04