Search⌘ K

Discovering Changes to the Reflection Extension

Discover how PHP 8 updates the Reflection extension with improved support for object-oriented introspection, enhanced methods for default values in internal functions, and new visibility filtering options. Learn to use these changes for better code analysis, automated documentation, and troubleshooting after migration.

The Reflection extension is used to perform introspection on objects, classes, methods, and functions, among other things. ReflectionClass and ReflectionObject produce information on a class or an object instance, respectively. ReflectionFunction provides information on procedural-level functions. In addition, the Reflection extension has a set of secondary classes produced by the main classes mentioned just now. These secondary classes include ReflectionMethod, produced by ReflectionClass::getMethod(), ReflectionProperty, produced by ReflectionClass::getProperty(), and so forth.

You might wonder: what uses this extension? The answer is any application that needs to perform analysis on an external set of classes. This might include software that performs automated code generation, testing, or documentation generation. Classes that perform hydration (populating objects from arrays) also benefit from the Reflection extension.

Tip: We do not have enough room to cover every single Reflection extension class and method. If we wish to get more information, please have a look at the documentation.

Let’s now have a look at a Reflection extension usage example.

Reflection extension usage

We will now show a code example that demonstrates how the Reflection ...