首页 话题 小组 问答 好文 用户 我的社区 域名交易 唠叨

[函数]class_implements()函数—用法及示例

发布于 2025-04-21 00:08:38
0
37

函数名:class_implements()

适用版本:5.0.2及以上版本

用法: class_implements() 函数用于返回一个类实现的所有接口的数组。

语法: array class_implements ( mixed $class [, bool $autoload = TRUE ] )

参数: $class:要检查的对象或类名。 $autoload:一个可选的布尔值参数,指定在找不到类时是否自动加载。默认为 true。

返回值: 成功时返回一个包含类实现的所有接口的数组,失败时返回 false。

示例:

interface MyInterface {
    public function hello();
}

class MyClass implements MyInterface {
    public function hello() {
        echo "Hello World!";
    }
}

$interfaces = class_implements('MyClass');
print_r($interfaces);

输出:

Array
(
    [MyInterface] => MyInterface
)

上述示例中,MyClass 类实现了 MyInterface 接口。通过调用 class_implements() 函数,我们得到了一个包含类实现的接口的数组 ["MyInterface" => "MyInterface"]。

评论
一个月内的热帖推荐
啊龙
Lv.1普通用户

9545

帖子

31

小组

3242

积分

赞助商广告
站长交流