Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP

ฟังก์ชัน get_class_methods() ใน PHP

คำอธิบาย

ฟังก์ชัน get_class_methods() คืนค่าอาร์เรย์ของชื่อเมธอดทั้งหมดที่ประกาศในคลาสที่ระบุ

รูปแบบการใช้งาน (Syntax)

get_class_methods(class)

พารามิเตอร์

  • class — ชื่อคลาสหรือออบเจ็กต์ (จำเป็น)

ค่าที่คืนกลับ

คืนค่าอาร์เรย์ชื่อเมธอด หรือ NULL หากเกิดข้อผิดพลาด

ตัวอย่างการใช้งาน

<?php
class Demo {
    function __construct() { return true; }
    function displayOne() { return true; }
    function displayTwo() { return true; }
}

$methods = get_class_methods('Demo');
$methods2 = get_class_methods(new Demo());

foreach ($methods as $method_name) {
    echo "$method_name\n";
}
?>

ผลลัพธ์

__construct
displayOne
displayTwo