zf1-future icon indicating copy to clipboard operation
zf1-future copied to clipboard

Unknown Named Parameter $match in Zend_Filter::filterStatic()

Open WebTigers opened this issue 1 year ago • 1 comments

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)

WebTigers avatar Dec 02 '23 21:12 WebTigers

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).

Screen Shot 2023-12-03 at 2 46 01 AM

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

WebTigers avatar Dec 03 '23 08:12 WebTigers