PHP 中的 interface_exists() 函数

phpprogrammingserver side programming更新于 2025/7/9 3:22:17

interface_exists() 函数检查接口是否已定义。如果 name_of_interface 指定的接口已定义,则返回 TRUE,否则返回 FALSE。

语法

interface_exists(name_of_interface, autoload)

参数

  • name_of_interface − 接口名称。

  • autoload − 是否默认调用 __autoload

返回值

如果 name_of_interface 指定的接口已定义,则 interface_exists() 函数返回 TRUE。否则返回 FALSE。

示例

下面是一个例子 −

<?php
   if (interface_exists('DemoInterface')) {
      class MyClass implements DemoInterface {
         // Methods
      }
   }
?>

相关文章