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

[zend-form] fix instantiating filters with options via addFilter() in php 8.0+ #194

Merged
merged 1 commit into from
Feb 25, 2024

Conversation

marcing
Copy link
Contributor

@marcing marcing commented Feb 13, 2024

PHP 8.0+ changes behaviour of ReflectionClass::newInstanceArgs, which now assumes that an associative array is an array of named parameters, trying to match array keys to names of arguments in the constructor. This leads to errors in Zend_Form_Element::_loadFilter.

$this->addFilter('Boolean', array('type' => Zend_Filter_Boolean::PHP + Zend_Filter_Boolean::FALSE_STRING));
zend-form\library\Zend\Form\Element.php:2117
Error: Unknown named parameter $type

Zend_Form_Element::_loadFilter has to be altered in the same manner as _loadValidator to call newInstanceArgs only or numerical arrays and call newInstance on associative arrays.

@marcing marcing changed the title test + fix PHP 8.0+ changes behaviour of ReflectionClass::newInstanceArgs Feb 13, 2024
@marcing marcing requested a review from falkenhawk February 13, 2024 17:19
@marcing marcing force-pushed the fix/php8-zend-form-element branch from 527acf7 to c210df9 Compare February 23, 2024 16:40
@marcing marcing force-pushed the fix/php8-zend-form-element branch from c210df9 to 26d082e Compare February 23, 2024 16:55
Copy link
Member

@falkenhawk falkenhawk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @marcing ! 💚

@falkenhawk falkenhawk marked this pull request as ready for review February 25, 2024 09:59
@falkenhawk falkenhawk changed the title PHP 8.0+ changes behaviour of ReflectionClass::newInstanceArgs [zend-form] fix instantiating filters with options via addFilter() in php 8.0+ Feb 25, 2024
@falkenhawk falkenhawk merged commit c8d2177 into master Feb 25, 2024
13 checks passed
@falkenhawk falkenhawk deleted the fix/php8-zend-form-element branch February 25, 2024 10:03
falkenhawk pushed a commit that referenced this pull request Feb 25, 2024
…in php 8.0+ (#194)

Copied logic from addValidator() to addFilter() which checks for array arguments and wraps them with additional array when necessary.
It's interesting that `addValidator()` was made future-proof already long time ago (even before the github history goes) but `addFilter()` was not
@falkenhawk falkenhawk mentioned this pull request Feb 25, 2024
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.

2 participants