ฟังก์ชั่น interface_exists()
ความหมายของฟังก์ชั่นและการใช้งาน
การตรวจสอบว่า ได้มีการกำหนดค่า interface ไว้หรือไม่ ด้วยฟังก์ชั่น interface_exists()
รูปแบบการเขียน (Syntax)
bool interface_exists ( string $interface_name [, bool $autoload = true ] )
ตัวอย่างที่ 1
<?php
// Check the interface exists before trying to use it
if (interface_exists('MyInterface')) {
class MyClass implements MyInterface
{
// Methods
}
}
?>
ตัวอย่างที่ 2
<?php
interface_exists(__NAMESPACE__ . '\MyInterface', false);
?>