ZF2-113: Uncaught ReflectionExcemption being thrown from within Zend\Loader\PluginBroker
Description
Under the following conditions it is possible for \Zend\Filter\FilterChain to cause an Uncaught ReflectionExeption to be thrown from within \Zend\Loader\PluginBroker::load()
Given the following code snippets:
class myFilter extends \Zend\Filter\AbstractFilter {
public function filter($text) {
return 'test';
}
}
$f = new \Zend\Filter\FilterChain(array(
'filters' => array(
'name' => 'myFilter'
),
));
Things seem to go awry within the \Zend\Filter\FilterChain::attachByName method when the $options array is empty. This results in: 1) an array with an empty array within it to (eventually) be sent to \Zend\Loader\Plugin::load() as the $options; 2) the above results in the incorrect logic to be executed within the load() method.
Comments
Posted by Shaun Bramley (shaunb) on 2011-12-06T17:48:28.000+0000
If no options (or an empty array) is passed to attachByName then the following conditional will evaluate true.
I propose altering the function to the following:
I will draw up a couple of tests when I get home tonight.
Posted by Matthew Weier O'Phinney (matthew) on 2011-12-08T22:30:37.000+0000
Based on your reproduce case, you've got incorrect structure in the array you're passing to the constructor of FilterChain. Each filter needs to be listed as an associative array itself:
When I do the above, I run into no issues whatsoever.
Posted by Matthew Weier O'Phinney (matthew) on 2011-12-08T22:31:47.000+0000
Cannot reproduce, and appears to be incorrect usage.
Posted by Shaun Bramley (shaunb) on 2011-12-08T23:34:11.000+0000
There's a typo within my original use case. I feel like an idiot now. :(
results in the following stack trace: Fatal error: Uncaught exception 'ReflectionException' with message 'Class myFilter does not have a constructor, so you cannot pass any constructor arguments' in /Users/shaunbramley/Downloads/ZendFramework-2.0.0dev3/library/Zend/Loader/PluginBroker.php:191 Stack trace:
0 /Users/shaunbramley/Downloads/ZendFramework-2.0.0dev3/library/Zend/Loader/PluginBroker.php(191): ReflectionClass->newInstanceArgs(Array)
1 /Users/shaunbramley/Downloads/ZendFramework-2.0.0dev3/library/Zend/Loader/PluginSpecBroker.php(179): Zend\Loader\PluginBroker->load('myFilter', Array)
2 /Users/shaunbramley/Downloads/ZendFramework-2.0.0dev3/library/Zend/Filter/FilterChain.php(143): Zend\Loader\PluginSpecBroker->load('myFilter', Array)
3 /Users/shaunbramley/Downloads/ZendFramework-2.0.0dev3/library/Zend/Filter/FilterChain.php(188): Zend\Filter\FilterChain->broker('myFilter', Array)
4 /Users/shaunbramley/Downloads/ZendFramework-2.0.0dev3/library/Zend/Filter/FilterChain.php(97): Zend\Filter\FilterChain->attachByName('myFilter', Array, 1000)
5 /Users/ in /Users/shaunbramley/Downloads/ZendFramework-2.0.0dev3/library/Zend/Loader/PluginBroker.php on line 191
Is my use case not adhering to the intended usage? I see no difference in the the files between master and beta3.
Posted by Jacek Karczmarczyk (gadjo) on 2012-01-17T05:21:26.000+0000
Confirming this with the standard "Int" filter (master branch)
Posted by John Smith (darksmith) on 2012-04-24T00:05:36.000+0000
I'm able to reproduce this with the Int filter and the StripNewlines filter. The range function will generate an array with two empty value in it when the options variable is empty.
Posted by Matthew Weier O'Phinney (matthew) on 2012-05-02T15:08:33.000+0000
Reproduced.
I've got a PR in for this now: https://github.com/zendframework/zf2/pull/1128
Posted by Matthew Weier O'Phinney (matthew) on 2012-05-02T15:21:13.000+0000
PR #1128 merged to master, fixing the issue.