ZF2-34: Array arguments get flattened when creating Zend\Log\Logger

Issue Type: Bug Created: 2011-07-13T17:29:31.000+0000 Last Updated: 2012-06-26T12:35:27.000+0000 Status: Resolved Fix version(s): Reporter: Artur Bodera (joust) Assignee: Enrico Zimuel (zimuel) Tags: - Zend\Loader

  • bug
  • loader
  • zf-crteam-padraic
  • zf-crteam-priority

Related issues: Attachments:


App configuration used:

<pre class="highlight">
                 'log'=> array (
                'writerName' => 'Stream',
                'writerParams' => array(
                    'stream' => APPLICATION_PATH.'/production.log',
                'formatterName' => 'Simple',
                'formatterParams' => array(
                    'format' => '%timestamp%    %priorityName%  %sessionid% %user%: %message%'.PHP_EOL,
                'filterName'   => 'Priority',
                'filterParams' => array(
                    'priority' => 4,        // warn


{quote} Fatal error: Uncaught exception 'Zend\Log\Exception\InvalidArgumentException' with message 'Writer must be an instance of Zend\Log\Writer or you should pass a configuration array' in /path/library/Zend/Log/Logger.php on line 484 {quote}

Because Zend\Log\Logger expects and array(array('name'=>'val')) configuration, but PluginBroker flattens the array. The flattening occurs in Zend/Loader/PluginBroker.php:191

<pre class="highlight">
        } else {
            $r = new \ReflectionClass($class);
            $instance = $r->newInstanceArgs($options);

When arriving at this function, $options contains array(array()). Then instance is created with just array() because of ReflectionClass::newInstanceArgs() (see…).


<pre class="highlight">
 $instance = $r->newInstanceArgs(array($options));

Workaround: Use a tripple-nested config for log, ie:

<pre class="highlight">
  'log' => array(array(array('writerName'=> ... ))),


Posted by Marc Bennewitz (private) (mabe) on 2012-05-02T10:36:40.000+0000

{quote} Fix:

<pre class="highlight">
$instance = $r->newInstanceArgs(array($options));


If thats the way to go it's not required to use reflection. A simple

<pre class="highlight">
$instance = new $class($options);

should be enough.

Posted by Maks 3w (maks3w) on 2012-06-06T11:23:27.000+0000

This is about Zend\Log

Posted by Maks 3w (maks3w) on 2012-06-06T11:29:25.000+0000

Artur, Zend\Log has been recently refactored. Is this still occurs?

Posted by Maks 3w (maks3w) on 2012-06-26T12:35:27.000+0000

The code affected by this issue has been refactored and now PluginBroker is not used by Zend\Log

Have you found an issue?

See the Overview section for more details.


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

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