What is Reflection in PHP?
Answer
PHP's Reflection API allows introspection of classes, interfaces, functions, methods, and properties at runtime. ReflectionClass, ReflectionMethod, ReflectionProperty, and ReflectionFunction are the main classes. Example: $ref = new ReflectionClass($object); $methods = $ref->getMethods(); $props = $ref->getProperties();. Reflection enables reading and instantiating classes from string names, accessing private members (for testing), reading method parameter types and defaults, and checking for attributes (PHP 8) or docblock annotations (older approach). Dependency injection containers use Reflection extensively to automatically resolve constructor dependencies. Reflection is powerful but has a performance cost — use it in bootstrapping/compilation phases rather than hot request paths.