

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 ) )
- Related Questions & Answers
- Attributes in PHP 8
- New Date-Time API in Java 8
- Named Arguments in PHP 8
- Union Type in PHP 8
- Number comparisons in PHP 8
- Match Expression in PHP 8
- Nullsafe Operator in PHP 8
- fdiv() function in PHP 8
- Reading/Writing a MS Word file in PHP
- How to print all attributes in StackFrame API in Java 9?
- Create array with Array.newInstance with Java Reflection
- Mixed Pseudo Type in PHP 8
- Constructor Property Promotion in PHP 8
- Reflection in C#
- Difference between gettype() in PHP and get_debug_type() in PHP 8
Advertisements