首页 文章资讯内容详情

抽象静态方法PHP中的实例子类?

2026-06-04 1 花语

为此,将$anyObjectName=newstatic()与self一起使用。

示例

PHP代码如下

<!DOCTYPE html> <html> <body> <?php abstract class Base{ protected static $fullName = ; abstract protected function customFunction(); public static function get_obj($param1 = null, $param2 = null){ $obj = new static(); $obj->customFunction(); } public static function getFullName(){ return static::$fullName; } } class Child extends Base { protected static $fullName = John Doe; protected function customFunction(){ echo self::getFullName() . "<br>"; echo $this; } } Child::get_obj(); ?> </body> </html>

输出结果

这将产生以下输出

John Doe