Hydrator not passing instance to filters on extract

Noticed that for most hydration implementations on the extract method the filtering happens only by property name or method name without passing an instance object, which in fact is a filter method optional second argument while still not passed in most implementations.
Now my concern is if that is a bug or if there is another reason behind it I simply don’t see.

Welcome to the Laminas community,

can you show us a reproducable code example? That would make things much more clearer.
Thanks in advance. :wink:

Sure @ezkimo here you go - minimum reproducible code


use Laminas\Hydrator\ReflectionHydrator;

require __DIR__ . '/vendor/autoload.php';

class Foo {
    protected DateTimeImmutable $ts;
$foo = new Foo();
$hydrator = new ReflectionHydrator();
$hydrator->addFilter('uninitialized', function (string $property, mixed $instance): bool {
    assert($instance instanceof Foo);
    return true;
$extracted = $hydrator->extract($foo);

The explanation can be found in the related release notes:

This argument’s primary use case is with anonymous objects, to facilitate reflection; the ClassMethodsHydrator , for instance, was updated to pass the $instance value only when an anonymous object is detected.

If you think this will be useful for more than anonymous objects, then please create a feature request and describe your use case. Thanks in advance! :+1:t3:

1 Like