Download the PHP package oihana/php-reflect without Composer
On this page you can find all versions of the php package oihana/php-reflect. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download oihana/php-reflect
More information about oihana/php-reflect
Files in oihana/php-reflect
Download oihana/php-reflect
More information about oihana/php-reflect
Files in oihana/php-reflect
Vendor oihana
Package php-reflect
Short Description The Oihana PHP Reflection library
License MPL-2.0
Homepage https://github.com/BcommeBois/oihana-php-reflect
Package php-reflect
Short Description The Oihana PHP Reflection library
License MPL-2.0
Homepage https://github.com/BcommeBois/oihana-php-reflect
Please rate this library. Is it a good library?
Informations about the package php-reflect
Oihana PHP - Reflect

Lightweight reflection and hydration helpers for modern PHP, part of the Oihana PHP ecosystem.
It provides:
- Friendly wrappers around PHP's Reflection API
- Array-to-object hydration with attribute-based mapping
- Utilities to expose public properties as arrays
- Simple constant βenumsβ helpers
- A compact
Versionvalue object
π Documentation
Full documentation: https://bcommebois.github.io/oihana-php-reflect
π¦ Installation
Requires PHP 8.4+
β¨ Features
Reflection helpers
- List constants, methods, properties with visibility filters
- Inspect method parameters: type, default, nullable, optional, variadic
- Inspect classes/properties:
hasMethod,hasProperty,propertyType,namespace(union types rendered asA|B, intersection asA&B) - Read instantiated attributes:
classAttributes,propertyAttributes,methodAttributes(optionally filtered by attribute class) - Describe any callableβs parameters (
describeCallableParameters) - Cached
ReflectionClassinstances
Hydration
- Instantiate and hydrate objects from associative arrays (recursively)
- Supports union types and nullability
- Attribute-based mapping:
#[HydrateKey('source_key')]to rename incoming keys (accepts several fallback keys:#[HydrateKey('user_name', 'username')]β first present wins)#[HydrateWith(Foo::class, Bar::class)]for arrays of objects, including polymorphism via@type/typeor property-guessing#[HydrateAs(Foo::class)]to override ambiguous types (object,array,mixed, unions)#[Transient](or its alias#[HydrateIgnore]) to exclude a public property from both hydration (input) andtoArray()(output) β e.g. computed/derived properties
- PHPDoc
@var Type[]and@var array<Type>support for array element types - Backed enums: scalar values are resolved to enum cases via
Enum::from()(single values, and arrays of enums via#[HydrateWith]or@var Enum[]). Pure (non-backed) enums have no scalar representation: hydrating one from a scalar throws anInvalidArgumentExceptionβ declare a backed enum instead DateTimeInterface: scalar values are resolved to date instances (string β parsed date, int β Unix timestamp). In a union with a scalar (e.g.string|DateTimeInterface), the raw value is kept unless#[HydrateAs(DateTimeImmutable::class)]forces the conversion- Classes with a required constructor: instantiated via
newInstanceWithoutConstructor()and populated from the data (a no-argument-callable constructor is still invoked normally) readonlyand asymmetric-visibility properties (public private(set)/public protected(set), PHP 8.4): values are assigned via reflection, so they are initialized correctly (scalar coercion preserved)- Scalar coercion: values are converted to the declared scalar type following PHP's coercive typing (
'42'βint 42,7βstring '7'); a value that cannot be coerced raises aHydrationException(independent ofstrict_types) - Error handling: every hydration failure throws a single catchable
HydrationException(extendsInvalidArgumentException), exposinggetClassName(),getPropertyName()and the original error viagetPrevious()β handy to skip an invalid record when hydrating a batch/stream - Symmetric serialization:
ReflectionTrait::toArray()serializesDateTimeInterfacevalues to ISO 8601 (overridable), and can emit#[HydrateKey]source keys (opt-in viaSerializeOption) β round-trip withhydrate() - Performance: a per-class hydration plan is cached on first use, so the data-independent reflection work (attributes,
@varitem types, constructor strategy, builtin types) is computed once and reused for every object of that class. The cache is in-memory, bounded by the number of hydrated classes, and needs no eviction. On nested documents this cuts hydration time by roughly a third (the deeper the nesting, the larger the gain)
Traits
ReflectionTraitconvenience layer andjsonSerializeFromPublicProperties()(with optional reduction)ConstantsTraitutilities over class constants:getAll,includes,enums,getConstant,validate
Value objects
Versionpacks major/minor/build/revision into a 32-bit int with configurable string output
π Quick start
Reflection basics
Describe any callable
Hydration: flat and nested
Hydration with attributes
Arrays of objects via PHPDoc
Polymorphic arrays with HydrateWith
Trait: ReflectionTrait
Trait: ConstantsTrait
Value object: Version
β Running Unit Tests
Run a specific test file:
π οΈ Generate the API Docs
We use phpDocumentor to generate the HTML docs into ./docs.
π§Ύ License
Licensed under the Mozilla Public License 2.0 (MPL-2.0). See LICENSE.
π€ Author
- Author: Marc ALCARAZ (aka eKameleon)
- Email: [email protected]
- Website:
http://www.ooop.fr
All versions of php-reflect with dependencies
PHP Build Version
Package Version
The package oihana/php-reflect contains the following files
Loading the files please wait ...