略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: ReflectionClass::isAbstract

2024-04-28

ReflectionClass::isAbstract

(PHP 5, PHP 7, PHP 8)

ReflectionClass::isAbstract检查类是否是抽象类(abstract)

说明

public ReflectionClass::isAbstract(): bool

检查这个类是否是抽象类(abstract)。

参数

此函数没有参数。

返回值

成功时返回 true, 或者在失败时返回 false

范例

示例 #1 ReflectionClass::isAbstract() 例子

<?php
class          TestClass { }
abstract class 
TestAbstractClass { }

$testClass     = new ReflectionClass('TestClass');
$abstractClass = new ReflectionClass('TestAbstractClass');

var_dump($testClass->isAbstract());
var_dump($abstractClass->isAbstract());
?>

以上例程会输出:

bool(false)
bool(true)

参见

add a noteadd a note

User Contributed Notes 1 note

up
2
baptiste at pillot dot fr
5 years ago
For interfaces and traits :

<?php
interface TestInterface { }
trait    
TestTrait { }

$interfaceClass = new ReflectionClass('TestInterface');
$traitClass     = new ReflectionClass('TestTrait');

var_dump($interfaceClass->isAbstract());
var_dump($traitClass->isAbstract());
?>

Using PHP versions 5.4- to 5.6, the above example will output:

bool(false)
bool(true)

Using PHP versions 7.0+, the above example will output:

bool(false)
bool(false)

官方地址:https://www.php.net/manual/en/reflectionclass.isabstract.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3