PHP 8-এ, আমরা ক্লাস, প্রোপার্টি, এবং ক্লাস কনস্ট্যান্ট, মেথড, ফাংশন, প্যারামিটার ব্যবহার করে attributes অ্যাক্সেস করি।
PHP 8-এ, Reflection API প্রতিটি মিলে যাওয়া Reflection অবজেক্টে getAttribute() মেথড প্রদান করে।
getAttribute() মেথড ReflectionAttribute ইলাস্ট্রেশনের একটি অ্যারে রিটার্ন করে যা attribute নাম, আর্গুমেন্ট এবং সিগনিফাইড attribute-এর একটি ইনস্ট্যান্স ইনস্ট্যানশিয়েট করার জন্য জিজ্ঞাসা করা যেতে পারে।
উদাহরণ − PHP 8-এ Reflection API ব্যবহার করে Attributes পড়া
<?php #[Reading] #[Property(type: 'function', name: 'Student')] function Student() { return "Student"; } function getAttributes(Reflector $reflection) { $attributes = $reflection->getAttributes(); $finalresult = []; foreach ($attributes as $attribute) { $finalresult[$attribute->getName() ] = $attribute->getArguments(); } return $finalresult; } $reflection = new ReflectionFunction("Student"); print_r(getAttributes($reflection)); ?>আউটপুট
Array ( [Reading] => Array ( ) [Property] => Array ( [type] => function [name] => Student ) )