Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading filter into form element #186

Merged
merged 1 commit into from
Jan 4, 2022
Merged

Conversation

MateuszPles
Copy link

If filter['options'] is not in array then I receviced exception

Message: Unknown named parameter $match

Stack trace:
#0 /var/www/html/vendor/shardj/zf1-future/library/Zend/Form/Element.php(2122): ReflectionClass->newInstanceArgs()
#1 /var/www/html/vendor/shardj/zf1-future/library/Zend/Form/Element.php(1779): Zend_Form_Element->_loadFilter()
#2 /var/www/html/vendor/shardj/zf1-future/library/Zend/Form/Element.php(593): Zend_Form_Element->getFilters()
#3 /var/www/html/vendor/shardj/zf1-future/library/Zend/Form/Element.php(610): Zend_Form_Element->_filterValue()
#4 /var/www/html/vendor/shardj/zf1-future/library/Zend/Form/Decorator/ViewHelper.php(206): Zend_Form_Element->getValue()
#5 /var/www/html/vendor/shardj/zf1-future/library/Zend/Form/Decorator/ViewHelper.php(236): Zend_Form_Decorator_ViewHelper->getValue()
#6 /var/www/html/vendor/shardj/zf1-future/library/Zend/Form/Element.php(2077): Zend_Form_Decorator_ViewHelper->render()
#7 /var/www/html/vendor/shardj/zf1-future/library/Zend/Form/Element.php(2092): Zend_Form_Element->render()
#8 /var/www/html/application/modules/invoice/views/scripts/document/partials/1.phtml(72): Zend_Form_Element->__toString()
#9 /var/www/html/vendor/shardj/zf1-future/library/Zend/View.php(157): include('...')
#10 /var/www/html/vendor/shardj/zf1-future/library/Zend/View/Abstract.php(887): Zend_View->_run()
#11 /var/www/html/vendor/shardj/zf1-future/library/Zend/View/Helper/Partial.php(109): Zend_View_Abstract->render()
#12 /var/www/html/vendor/shardj/zf1-future/library/Zend/View/Abstract.php(349): Zend_View_Helper_Partial->partial()
#13 /var/www/html/vendor/shardj/zf1-future/library/Zend/Form/Decorator/ViewScript.php(175): Zend_View_Abstract->__call()
#14 /var/www/html/vendor/shardj/zf1-future/library/Zend/Form.php(2993): Zend_Form_Decorator_ViewScript->render()
#15 /var/www/html/library/Twitter/Bootstrap/Form.php(199): Zend_Form->render()
#16 /var/www/html/vendor/shardj/zf1-future/library/Zend/Form.php(3009): Twitter_Bootstrap_Form->render()
#17 /var/www/html/application/modules/invoice/views/scripts/document/edit.phtml(13): Zend_Form->__toString()
#18 /var/www/html/vendor/shardj/zf1-future/library/Zend/View.php(157): include('...')
#19 /var/www/html/vendor/shardj/zf1-future/library/Zend/View/Abstract.php(887): Zend_View->_run()
#20 /var/www/html/vendor/shardj/zf1-future/library/Zend/Controller/Action/Helper/ViewRenderer.php(910): Zend_View_Abstract->render()
#21 /var/www/html/vendor/shardj/zf1-future/library/Zend/Controller/Action/Helper/ViewRenderer.php(931): Zend_Controller_Action_Helper_ViewRenderer->renderScript()
#22 /var/www/html/vendor/shardj/zf1-future/library/Zend/Controller/Action/Helper/ViewRenderer.php(970): Zend_Controller_Action_Helper_ViewRenderer->render()
#23 /var/www/html/vendor/shardj/zf1-future/library/Zend/Controller/Action/HelperBroker.php(277): Zend_Controller_Action_Helper_ViewRenderer->postDispatch()
#24 /var/www/html/vendor/shardj/zf1-future/library/Zend/Controller/Action.php(527): Zend_Controller_Action_HelperBroker->notifyPostDispatch()
#25 /var/www/html/vendor/shardj/zf1-future/library/Zend/Controller/Dispatcher/Standard.php(308): Zend_Controller_Action->dispatch()
#26 /var/www/html/vendor/shardj/zf1-future/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch()
#27 /var/www/html/vendor/shardj/zf1-future/library/Zend/Application/Bootstrap/Bootstrap.php(105): Zend_Controller_Front->dispatch()
#28 /var/www/html/vendor/shardj/zf1-future/library/Zend/Application.php(384): Zend_Application_Bootstrap_Bootstrap->run()
#29 /var/www/html/public/index.php(27): Zend_Application->run()
#30 {main}

@MateuszPles
Copy link
Author

I've tested my fix in php version 7.1, 7.4, 8.0. For all those version it is working properly.

@Shardj Shardj merged commit dabc2c3 into Shardj:master Jan 4, 2022
@SiCoUK
Copy link

SiCoUK commented Mar 7, 2022

I didn't know whether to bring this back to life or comment on the commit but the fix breaks compatibility for filters with constructor arguments (options).

I would guess it isn't widely used as the default filters don't appear to use it, however, you used to be able to define a filter for a form like so:

array('Between', [1, 30])

The arguments would be passed to the filter as constructor arguments which is how I believe this was supposed to work. Now however this array is wrapped inside another array and no longer works as expected.

p.s. I've only just started using this package in order to upgrade my code to PHP 8 and this is the first issue I've come across.

@Shardj
Copy link
Owner

Shardj commented Mar 8, 2022

@SiCoUK if you could make another PR to try and resolve the new issue you've found that would be great 👍 thanks for your help

Looking back, I'm not sure why wrapping $filter['options'] in another array like the merged code would help. Probably just needed a null coalescing operator against $filter['options'] to give it a default value of [] if 'options' weren't set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants