Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Reflector

Reflector is the base interface that all PHP Reflection classes implement. It declares __toString(), providing a common type for all reflection objects.

All reflection classes, ReflectionClass, ReflectionMethod, ReflectionFunction, ReflectionProperty, ReflectionParameter, etc., implement this interface, allowing code to accept any reflector generically.

<?php

    function describeReflector(Reflector $r): void {
        echo (string) $r . PHP_EOL;
    }
    
    describeReflector(new ReflectionClass(DateTime::class));
    describeReflector(new ReflectionFunction('array_map'));

?>

Documentation

See Also