interface_exists

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

interface_exists检查接口是否已被定义

说明

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

检查接口是否已被定义。

参数

interface

接口名。

autoload

如果尚未加载,是否自动加载

返回值

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

示例

示例 #1 interface_exists() 示例

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

?>

参见

To Top