# Reflection API

> Section in “New and Extended Functionality” of the book [PHP 7 Explained](https://php7explained.com/) by Sebastian Bergmann and Stefan Priebsch, published by thePHP.cc. The book covers PHP 7.0 to 7.4 and was last updated in November 2020. HTML version: <https://php7explained.com/new-and-extended-functionality/reflection-api/>

Originally introduced in PHP 5, the Reflection API allows a PHP program to introspect code structures at runtime. Valid use cases for this examination of classes and methods, for instance, include object-relational mappers and test double libraries. Not least because of performance reasons, the usage of the Reflection API should be kept to a minimum for code that is used in production.

For PHP 7, the Reflection API has been extended to support the introspection of scalar type declarations, return type declarations, and generator functions (generators).

## In this section

- [Scalar Type Declarations](https://php7explained.com/new-and-extended-functionality/reflection-api/scalar-type-declarations/index.html.md): Reflection of type declarations: ReflectionParameter::hasType() and getType(), ReflectionType, ReflectionNamedType::getName(), and getReturnType().
- [Generators](https://php7explained.com/new-and-extended-functionality/reflection-api/generators/index.html.md): The ReflectionGenerator class introspects Generator objects with methods such as getExecutingFile(), getExecutingLine(), getFunction(), and getTrace().
- [References](https://php7explained.com/new-and-extended-functionality/reflection-api/references/index.html.md): The ReflectionReference class detects references: fromArrayElement() returns an object if an array element holds a reference, and getId() identifies it.

---

Previous: [Same-Site Cookies](https://php7explained.com/new-and-extended-functionality/cryptography-and-security/same-site-cookies/index.html.md) | Next: [Scalar Type Declarations](https://php7explained.com/new-and-extended-functionality/reflection-api/scalar-type-declarations/index.html.md)
