interface_exists 检查接口是否已被定义

发表日期:2021-07-01 08:57:11 | 来源: | | 浏览(790) 分类:类/对象 函数

interface_exists

(PHP 5 >= 5.0.2, PHP 7, PHP 8)

interface_exists检查接口是否已被定义

说明

interface_exists(string $interface_name, bool $autoload = true): bool

检查接口是否已被定义。

参数

interface_name

接口名。

autoload

默认是否调用 __autoload。

返回值

本函数在由 interface_name 给出的接口已定义时返回 true,否则返回 false

范例

示例 #1 interface_exists() 例子

<?php 
// 在尝试使用前先检查接口是否存在if (interface_exists('MyInterface')) {
    class MyClass implements MyInterface    {
        // Methods    }
}
?>

参见

集速网 copyRight © 2015-2022 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。