【发布时间】:2013-08-12 20:59:35
【问题描述】:
鉴于以下代码,我正在寻找调用 $this->myStaticFunc(); 的优点和缺点; vs self::myStaticFunc();
class MyClass
private function myPrivateFunc() {
...
$this->myStaticFunc(); // or self::myStaticFunc();
...
}
// no need to tell me that i can't use $this in here
public static function myStaticFunc() { ... }
}
// access static function
MyClass::myStaticFunc();
【问题讨论】:
-
给你零信息,想知道我该买黑色还是蓝色车...
-
它们的用途完全不同......如果你的函数需要针对实例工作,那么你将它称为实例函数;如果没有,那么你可以使用静态函数
标签: php static function-call