ফাংশন get_declared_interfaces

ফাংশন get_declared_interfaces বর্তমান স্ক্রিপ্টে ঘোষিত বা অটোলোডের মাধ্যমে লোড করা সমস্ত ইন্টারফেসের নামের একটি অ্যারে ফেরত দেয়। ফাংশনটি কোনো প্যারামিটার গ্রহণ করে না।

সিনট্যাক্স

phpget_declared_interfaces();

উদাহরণ

আসুন ঘোষিত সমস্ত ইন্টারফেসের তালিকা নেওয়া যাক:

php<?php
  interface MyInterface1 {}
  interface MyInterface2 {}
  
  $res = get_declared_interfaces();
  print_r($res);
?>

কোড 실행ের ফলাফল:

php[..., 'MyInterface1', 'MyInterface2']

উদাহরণ

আসুন পরীক্ষা করে দেখি তালিকায় একটি নির্দিষ্ট ইন্টারফেস আছে কিনা:

php<?php
  interface LoggerInterface {}
  
  $interfaces = get_declared_interfaces();
  $res = in_array('LoggerInterface', $interfaces);
  var_dump($res);
?>

কোড 실행ের ফলাফল:

phptrue

উদাহরণ

আসুন একটি নতুন ইন্টারফেস ঘোষণার আগে এবং পরে ইন্টারফেসের তালিকা তুলনা করি:

php<?php
  $before = get_declared_interfaces();
  interface NewInterface {}
  $after = get_declared_interfaces();
  
  $res = array_diff($after, $before);
  print_r($res);
?>

কোড 실행ের ফলাফল:

php['NewInterface']

আরও দেখুন

  • ফাংশন get_declared_classes,
    যা ক্লাসগুলি ফেরত দেয়
  • ফাংশন get_declared_traits,
    যা ট্রেইটগুলি ফেরত দেয়
  • ফাংশন interface_exists,
    যা একটি ইন্টারফেস পরীক্ষা করে
  • ফাংশন class_implements,
    যা একটি ক্লাসের ইন্টারফেসগুলি ফেরত দেয়