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

Description

App configuration used:


                 'log'=> array (
            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
                ),
            ),
        ),

Result:

{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


        } 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 http://php.net/manual/en/…).

Fix:


 $instance = $r->newInstanceArgs(array($options));

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


  'log' => array(array(array('writerName'=> ... ))),

Comments

{quote} Fix:


$instance = $r->newInstanceArgs(array($options));

{quote}

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


$instance = new $class($options);

should be enough.

This is about Zend\Log

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

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