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
Posted by Marc Bennewitz (private) (mabe) on 2012-05-02T10:36:40.000+0000
{quote} Fix:
{quote}
If thats the way to go it's not required to use reflection. A simple
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