PHP抽象類可以包含靜態(tài)方法。靜態(tài)方法是屬于類而不是對(duì)象的,因此抽象類可以定義靜態(tài)方法。在抽象類中定義的靜態(tài)方法可以直接通過(guò)類名調(diào)用,而不需要實(shí)例化對(duì)象。示例代碼如下:
abstract class AbstractClass {
public abstract function someMethod();
public static function staticMethod() {
echo "This is a static method in the abstract class.";
}
}
AbstractClass::staticMethod(); // 輸出:This is a static method in the abstract class.