zf1-future
zf1-future copied to clipboard
Unknown Named Parameter $match in Zend_Filter::filterStatic()
This code works in PHP 7.4
if ( isset($params['method']) ) {
$method = Zend_Filter::filterStatic(
$params['method'],
'PregReplace', array('match' => '/[^A-Za-z0-9_]/', 'replace' => '')
);
$this->{$method}($params);
}
Fails in PHP 8.1.23
Exception information: Message: Unknown named parameter $match
Stack trace: #0 .../vendor/shardj/zf1-future/library/Zend/Filter.php(229): ReflectionClass->newInstanceArgs(Array) #1 .../application/services/Ad.php(81): Zend_Filter::filterStatic('getReferralAdDa...', 'PregReplace', Array)
Solution
It appears that the issue is with passing named parameters into the newInstanceArgs() method of the Reflection class. In PHP 7 this gets ignored, but it doesn't get ignored in PHP 8 and tosses an exception.
The solution is to update the ZF1 code as follows (example):
$object = $class->newInstanceArgs( $args );
becomes
$object = $class->newInstanceArgs( array_values( $args ) );
The following files are affected and need to be tested (see screen shot of IDE showing files affected).
I tested this locally on the Zend_Filter::filterStatic() method and it works, but I don't have a testing environment setup yet. If someone wants to jump in for the fix I will send you a Starbucks! :D