PHP theorytheory 0/50 · 0%
Fundamentals · hard

44. Reflection API

Introspecting code at runtime.

The Reflection API (ReflectionClass, ReflectionMethod, ReflectionProperty, etc.) lets code inspect classes, methods, properties, and attributes at runtime, including private members. It underlies dependency injection containers, ORMs, and serialization libraries that need to construct objects and read metadata generically.

While powerful, reflection carries a performance cost compared to direct code, so frameworks typically cache reflection results rather than re-analyzing classes on every request.

Check your understanding

  1. 1. What is a primary real-world use of the Reflection API?

  2. 2. Can Reflection access private properties/methods?