淺談PHP中靜態(tài)方法和非靜態(tài)方法的相互調(diào)用
在PHP的非靜態(tài)方法中可以調(diào)用靜態(tài)方法
class test{
public static function strPrint(){
echo 'this is strPrint static function<br>';
}
public function staticFuncInvoke(){
self::strPrint();
}
}
$test = new test();
$test->staticFuncInvoke();
上面的代碼會輸出: this is strPrint static function.
而下面的代碼會直接掛掉,php直接給出fatal error:
Fatal error: Using $this when not in object context in E:\htdocs\test\content.php on line 6
class test{
public static function strPrint(){
$this->staticFuncInvoke();
}
public function staticFuncInvoke(){
echo 'this is a nonstatic function named staticFuncInvoke';
}
}
test::strPrint();
以上就是小編為大家?guī)淼臏\談PHP中靜態(tài)方法和非靜態(tài)方法的相互調(diào)用全部內(nèi)容了,希望大家多多支持腳本之家~
- 詳談php靜態(tài)方法及普通方法的區(qū)別
- php面向?qū)ο笾衧tatic靜態(tài)屬性和靜態(tài)方法的調(diào)用
- 淺析php靜態(tài)方法與非靜態(tài)方法的用法區(qū)別
- php中類和對象:靜態(tài)屬性、靜態(tài)方法
- PHP使用靜態(tài)方法的幾個注意事項
- PHP靜態(tài)調(diào)用非靜態(tài)方法的應(yīng)用分析
- php 靜態(tài)屬性和靜態(tài)方法區(qū)別詳解
- PHP靜態(tài)方法和靜態(tài)屬性及常量屬性的區(qū)別與介紹
- PHP實現(xiàn)偽靜態(tài)方法匯總
- php之static靜態(tài)屬性與靜態(tài)方法實例分析
- PHP的靜態(tài)方法與普通方法用法實例分析
相關(guān)文章
discuz免激活同步登入代碼修改方法(discuz同步登錄)
無需激活直接同步登入discuz,測試版本:discuz! x3,理論也支持2.5,大家測試再用吧2013-12-12
CI使用Tank Auth轉(zhuǎn)移數(shù)據(jù)庫導(dǎo)致密碼用戶錯誤的解決辦法
Tank Auth是針對Codeigniter的權(quán)限管理類庫,功能很強大。但是將數(shù)據(jù)庫轉(zhuǎn)到另一臺服務(wù)器上,會出現(xiàn)之前的用戶名和密碼都無法登錄的情況。這篇文章主要介紹了CI使用Tank Auth轉(zhuǎn)移數(shù)據(jù)庫導(dǎo)致密碼用戶錯誤的解決辦法,需要的朋友可以參考下2014-06-06
centos+php+coreseek+sphinx+mysql之一coreseek安裝篇
這篇文章主要介紹了centos+php+coreseek+sphinx+mysql之一coreseek安裝篇的相關(guān)資料,非常不錯具有參考借鑒價值,需要的朋友可以參考下2016-10-10

