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

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

Open
WebTigers opened this issue Dec 2, 2023 · 1 comment
Open

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

WebTigers opened this issue Dec 2, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@WebTigers
Copy link

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants