Download the PHP package bentools/reflection-plus without Composer
On this page you can find all versions of the php package bentools/reflection-plus. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bentools/reflection-plus
More information about bentools/reflection-plus
Files in bentools/reflection-plus
Package reflection-plus
Short Description Another improved code reflection API
License MIT
Informations about the package reflection-plus
Reflection Plus!
ReflectionPlus is a lightweight wrapper around PHP's native Reflection API that makes working with reflection simpler, more efficient, and more intuitive.
Features
- Cache-enabled reflection: Automatically caches reflection instances for better performance
- Simplified API: Clean, intuitive methods for accessing reflection information
- Type compatibility analysis: Easily determine if classes are compatible with property types
- Support for complex type systems: Full handling of union types, intersection types, and named types
- Performance optimized: Uses WeakMap and other optimizations to minimize memory usage
Why?
ReflectionPlus automatically caches:
- ReflectionClass instances
- ReflectionProperty instances
- ReflectionMethod instances
- Type compatibility results
This makes it highly efficient for repeated usage, especially in loops or recursive operations.
Use Cases
ReflectionPlus is particularly useful for:
- Factory implementations that need to determine which concrete classes to instantiate
- Dependency injection containers
- Type-based serialization/deserialization systems
- Code generators that need to inspect class structures
- Data mappers that need to determine type compatibility
- Framework development where reflection is frequently used
Requirements
- PHP 8.4 or higher
Usage
Basic Reflection Operations
Get a reflection class:
Get a reflection property:
Get a reflection method:
Working with Property Types
Get all instantiable class types that can be set to a property:
Check if a class is compatible with a property:
Find the best class for a property from a list of candidates:
Type Compatibility
Check type compatibility with different type systems:
Advanced Use Cases
Working with Union Types
Working with Intersection Types
Installation
You can install the package via composer:
License
MIT.