PHP 8 में, हम विशेषताओं तक पहुँचने के लिए कक्षाओं, गुणों और वर्ग स्थिरांक, विधियों, कार्यों, मापदंडों का उपयोग करते हैं।
PHP 8 में, प्रतिबिंब API getAttribute() वितरित करता है प्रत्येक मिलान परावर्तन वस्तु पर विधि।
getAttribute() विधि ReflectionAttribute . की एक सरणी देता है उदाहरण जो विशेषता नाम, तर्कों और संकेतित विशेषता के एक उदाहरण को तत्काल करने के लिए कहा जा सकता है।
उदाहरण - PHP 8 में परावर्तन API के साथ विशेषताओं को पढ़ना
<?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 ) )