Skip to content

Reflection

Raxos Reflection wraps PHP's native ReflectionClass, ReflectionMethod, ReflectionProperty, ReflectionParameter and ReflectionFunction in small, readonly reflector classes with a consistent, typed API. Every reflector can read PHP attributes through the shared Attributable trait, and a dedicated TypeReflector introspects and validates types, including unions, intersections, enums and iterables. The package is a foundational dependency used across Raxos for attribute driven features such as ORM models, router controllers and dependency injection.

Highlights

Explore by category

  • Reflectors: obtain a ClassReflector with the reflect() helper and walk a class, its properties, methods and hierarchy as typed reflector objects.
  • Reading attributes: how the Attributable trait exposes PHP attribute instances the same way on every reflector.
  • Working with types: use TypeReflector to classify and validate PHP types, from scalars and classes to enums, unions and intersections.

Quick example

php
<?php
declare(strict_types=1);

use function Raxos\Reflection\reflect;

$reflector = reflect(User::class);

foreach ($reflector->getPublicProperties() as $property) {
    echo $property->getName() . ': ' . $property->getType()->getName() . "\n";
}

Installation

Install the package with Composer and check the requirements on the installation page.

shell
composer require raxos/reflection