webservco / reflection
A PHP component/library. Small reflection helpers for inspecting a class and its constructor parameters.
v2.3.0
2026-10-11 16:34 UTC
Requires
- php: ^8.4
Requires (Dev)
- pds/skeleton: ^1
- phan/phan: ^6
- php-parallel-lint/php-console-highlighter: ^1
- php-parallel-lint/php-parallel-lint: ^1
- phpmd/phpmd: ^3
- phpstan/phpstan: ^2
- phpstan/phpstan-deprecation-rules: ^2
- phpstan/phpstan-phpunit: ^2
- phpstan/phpstan-strict-rules: ^2
- phpunit/phpunit: ^13
- slevomat/coding-standard: ^8
- squizlabs/php_codesniffer: ^4
- vimeo/psalm: ^6
- webservco/coding-standards: ^2
- webservco/component-common: ^2
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A PHP component/library. Please see webservco/sandbox for an example project using these types of components.
Small reflection helpers for inspecting a class and its constructor parameters.
- Related:
webservco/controller(checks controller constructors with it)
Installation
composer require webservco/reflection
Usage
use WebServCo\Reflection\Factory\ReflectionClassFactory; use WebServCo\Reflection\Service\ReflectionService; // \WebServCo\Reflection\Contract\ReflectionServiceInterface $reflectionService = new ReflectionService(new ReflectionClassFactory()); // Type of the second constructor parameter. Indexes start at 1. $type = $reflectionService->getConstructorParameterTypeAtIndex(TestController::class, 2); // \ReflectionClass $reflectionClass = $reflectionService->getReflectionClass(TestController::class);
Contracts
| Interface | Implementation | Purpose |
|---|---|---|
Contract\ReflectionServiceInterface |
Service\ReflectionService |
Class, constructor, and constructor parameters by index. |
Contract\ReflectionClassFactoryInterface |
Factory\ReflectionClassFactory |
Creates ReflectionClass objects. |
Namespaces are relative to WebServCo\Reflection\.
Notes
The service caches each ReflectionClass it creates and reuses it for the same class. Parameter indexes start at 1, like the parameter's position in the code. A missing constructor or parameter throws an exception instead of returning null, and so does a union or intersection type.
Development
# Start project. ddev start # Install dependencies. ddev c u # Run all validations. ddev c c # Run unit tests. ddev c test:dox