- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Reading Attributes with Reflection API in PHP 8
In PHP 8, we use classes, properties, and class constants, methods, functions, parameters to access the attributes.
In PHP 8, Reflection API delivers the getAttribute() method on every matching Reflection object.
The getAttribute() method returns an array of ReflectionAttribute illustrations that can be asked for attribute name, arguments and to instantiate an instance of the signified attribute.
Example − Reading Attributes with the Reflection API in PHP 8
<?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)); ?>
Output
Array ( [Reading] => Array ( ) [Property] => Array ( [type] => function [name] => Student ) )
Advertisements
To Continue Learning Please Login
Login with Google