zendframework / zend-stdlib

Stdlib component from Zend Framework
BSD 3-Clause "New" or "Revised" License
384 stars 76 forks source link

Zend\Stdlib\Hydrator is not fully backwards-compatible with Zend\Hydrator #34

Closed prolic closed 5 years ago

prolic commented 8 years ago

See for reference: https://github.com/phpro/zf-doctrine-hydration-module/issues/20

also related: https://github.com/zfcampus/zf-apigility-doctrine/issues/234

boesing commented 7 years ago

Actually, the AbstractHydrator of v2.7.0 has BC breaks to v2.6.0 as it doesn't implement zendframework/zend-stdlib interfaces like StrategyEnabledInterface, e.g.

Therefore, any code that depends on those interfaces (e.g. by typehinting them in method definitions), cannot upgrade to v2.7.0.

Bad example but this might show the problem pretty clear:

<?php

class MyHydratorWhichAlwaysHadStrategyEnabledInterfaceFromStdlib extends \Zend\Stdlib\Hydrator\AbstractHydrator
{
    // Implementation
}

class Service
{

    private $hydrator;

    public function __construct(MyHydratorWhichAlwaysHadStrategyEnabledInterfaceFromStdlib $hydrator)
    {
        // Yes we could use interface typehinting but however
        $this->hydrator = $hydrator;
    }

    public function doSomething()
    {
        // do some fancy stuff

        // Attach some custom strategies
        $this->attachCustomStrategies($this->hydrator);
    }

    private function attachCustomStrategies(\Zend\Stdlib\Hydrator\StrategyEnabledInterface $hydrator)
    {
        // Work with that interface
    }
}

Well now, the argumentation could be "Why wont you just check the interface before using the Method. Okay, I could do that, but anyways, the code wont getting executed at all then.

Proper way would be to migrate our code to the new interfaces introduced with zendframework/zend-hydrator but actually this could have side-effects in our code which contains more than a few lines.

However, any reasons why the interfaces are not implemented in zendframework/zend-stdlib AbstractHydrator? Just wondering, this would've been the best way to ensure BC. Dont wont to start a discussion, just a little hint to understand these changes for myself.

PowerKiKi commented 5 years ago

Related issues have all have been closed, and this one should be closed too, because it now is obsolete.