ฟังก์ชัน spl_autoload_functions

ฟังก์ชัน spl_autoload_functions ส่งกลับอาร์เรย์ของฟังก์ชันโหลดอัตโนมัติทั้งหมดที่ลงทะเบียนด้วย spl_autoload_register หากไม่มีตัวโหลดอัตโนมัติที่ลงทะเบียน ฟังก์ชันจะส่งกลับอาร์เรย์ว่าง

ไวยากรณ์

phpspl_autoload_functions();

ตัวอย่าง

ตรวจสอบรายการตัวโหลดอัตโนมัติที่ลงทะเบียนโดยไม่มีการลงทะเบียน:

php<?php
  $res = spl_autoload_functions();
  print_r($res);
?>

ผลลัพธ์การทำงานโค้ด:

php[]

ตัวอย่าง

ลงทะเบียนตัวโหลดอัตโนมัติและตรวจสอบผลลัพธ์:

php<?php
  function my_autoload($class) {
    include $class . '.php';
  }
  
  spl_autoload_register('my_autoload');
  $res = spl_autoload_functions();
  print_r($res);
?>

ผลลัพธ์การทำงานโค้ด:

php['my_autoload']

ตัวอย่าง

ตรวจสอบตัวโหลดอัตโนมัติที่ลงทะเบียนหลายตัว:

php<?php
  function autoload1($class) {
    // การใช้งาน 1
  }
  
  function autoload2($class) {
    // การใช้งาน 2
  }
  
  spl_autoload_register('autoload1');
  spl_autoload_register('autoload2');
  $res = spl_autoload_functions();
  print_r($res);
?>

ผลลัพธ์การทำงานโค้ด:

php['autoload1', 'autoload2']

ดูเพิ่มเติม

  • ฟังก์ชัน spl_autoload_register,
    ซึ่งทำการลงทะเบียนตัวโหลดอัตโนมัติ
  • ฟังก์ชัน spl_autoload_unregister,
    ซึ่งลบตัวโหลดอัตโนมัติ
  • ฟังก์ชัน spl_autoload_call,
    ซึ่งเรียกใช้ตัวโหลดอัตโนมัติ
  • ฟังก์ชัน class_exists,
    ซึ่งตรวจสอบคลาส