ZF2-284: DI reused "shared" parameters for dependencies, which crates unexpected problems

Issue Type: Bug Created: 2012-05-01T20:39:41.000+0000 Last Updated: 2012-10-08T20:15:19.000+0000 Status: Closed Fix version(s): Reporter: Bas K (bas) Assignee: Ralph Schindler (ralph) Tags: - Zend\Di

  • di-parameter-dependancies

Related issues: Attachments:


I ran into a situation in which DI is attempting to inject the wrong options parameter to an incorrect 'dependant' class.


but it boils down to DI trying to inject 'my-service-configuration' as options to Filesystem which is an CacheAdapter instantiated by the CacheFactory::factory

<pre class="highlight">
'My\Service' => array( /* LocatorAware, LoggerAware, mimic CacheAware */ 
                'parameters' => array( 
                    'options'      => 'my-service-configuration', /* is a My\ServiceOptions instance */ 
                    'logger'       => 'my-logger', /* is a Logger instance */ 
                    'cache'        => 'my-cache-adapter',  /* is a AdapterInteface instance */ 

relevant module.conf.php at


<pre class="highlight">
#0 .../vendor/ZendFramework/library/Zend/Stdlib/Options.php(41): Zend\Stdlib\Options->setFromArray(Object(My\ServiceOptions)) 
#1 .../vendor/ZendFramework/library/Zend/Cache/Storage/Adapter/Filesystem.php(82): Zend\Stdlib\Options->__construct(Object(My\ServiceOptions)) 
#2 [internal function]: Zend\Cache\Storage\Adapter\Filesystem->setOptions(Object(My\ServiceOptions)) 
#3 .../vendor/ZendFramework/library/Zend/Di/Di.php(394): call_user_func_array(Array, Array) 
#4 .../vendor/ZendFramework/library/Zend/Di/Di.php(212): Zend\Di\Di->handleInjectionMethodForInstance(Object(Zend\Cache\Storage\Adapter\Filesystem), 'setOptions', Array, 'my-cache-ada...', false) 
#5 .../vendor/ZendFramework/library/Zend/Di/Di.php(130): Zend\Di\Di->newInstance('my-cache-ada...', Array) 
#6 .../vendor/ZendFramework/library/Zend/Di/Di.php(609): Zend\Di\Di->get('my-cache-ada...', Array) 
#7 .../vendor/ZendFramework/library/Zend/Di/Di.php(389): Zend\Di\Di->resolveMethodParameters('My\Service...', 'setCache', Array, false, 'my-service', false) 
#8 .../vendor/ZendFramework/library/Zend/Di/Di.php(212): Zend\Di\Di->handleInjectionMethodForInstance(Object(My\Service), 'setCache', Array, 'my-service', false) 
#9 .../vendor/ZendFramework/library/Zend/Di/Di.php(130): Zend\Di\Di->newInstance('my-service', Array) 
#10 .../module/MyService/Module.php(46): Zend\Di\Di->get('my-service') 


Posted by Bas K (bas) on 2012-05-01T20:45:34.000+0000

Changing My\Service constructor to consume $serviceOptions is has been confirmed to avoid this problem.

Posted by Ralph Schindler (ralph) on 2012-10-08T20:15:19.000+0000

This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit:

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.