International PHP Conference Munich 2025

ReflectionMethod::isAbstract

(PHP 5, PHP 7, PHP 8)

ReflectionMethod::isAbstract判断方法是否是抽象方法

说明

public ReflectionMethod::isAbstract(): bool

判断方法是否是抽象方法

参数

此函数没有参数。

返回值

如果是抽象方法返回 true,否则返回 false

参见

添加备注

用户贡献的备注 1 note

up
0
bobray99 at gmail dot com
2 hours ago
This is an example using ReflectionMethod() to check if the parent class method is abstract or not. Calling an abstract method of a parent class will crash PHP.

<?php
abstract class modProcessor {
abstract public function
process();
}

class
ConcreteClass extends modProcessor {

public function
process() {
$reflectionMethod = new ReflectionMethod('modProcessor', 'process');
if (!
$reflectionMethod->isAbstract()) {
parent::process();
} else {
echo
"Cannot call abstract parent method";
}
}
}

$c = new ConcreteClass($modx);

$c->process();
To Top