在php的非静态方法中可以调用静态方法
class test{
public static function strPrint(){
echo 'this is strPrint static function
';
}
public function staticFuncInvoke(){
self::strPrint();
}
}
$test = new test();
$test->staticFuncInvoke();
上面的代码会输出: this is strPrint static function.
而下面的代码会直接挂掉,php直接给出fatal error:
立即学习“PHP免费学习笔记(深入)”;
Fatal error: Using $this when not in object context in E:\htdocs\test\content.php on line 6
功能列表:底层程序与前台页面分离的效果,对页面的修改无需改动任何程序代码。完善的标签系统,支持自定义标签,公用标签,快捷标签,动态标签,静态标签等等,支持标签内的vbs语法,原则上运用这些标签可以制作出任何想要的页面效果。兼容原来的栏目系统,可以很方便的插入一个栏目或者一个栏目组到页面的任何位置。底层模版解析程序具有非常高的效率,稳定性和容错性,即使模版中有错误的标签也不会影响页面的显示。所有的标
class test{
public static function strPrint(){
$this->staticFuncInvoke();
}
public function staticFuncInvoke(){
echo 'this is a nonstatic function named staticFuncInvoke';
}
}
test::strPrint();
以上就是小编为大家带来的浅谈PHP中静态方法和非静态方法的相互调用全部内容了,希望大家多多支持PHP中文网~
更多浅谈PHP中静态方法和非静态方法的相互调用相关文章请关注PHP中文网!










