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

invalid ParamNameMismatch with classes extending php_user_filter #10662

Closed
pilif opened this issue Feb 6, 2024 · 3 comments · Fixed by #10666
Closed

invalid ParamNameMismatch with classes extending php_user_filter #10662

pilif opened this issue Feb 6, 2024 · 3 comments · Fixed by #10666

Comments

@pilif
Copy link
Contributor

pilif commented Feb 6, 2024

https://psalm.dev/r/f3e7bae361

the method's third parameter is supposed to be consumed, not rw_consumed. See https://www.php.net/php_user_filter

I think the rw_-prefix comes from the callmap because the parameter is in/out and those prefixes should probably be ignored in general when checking for parameter name matching.

Copy link

I found these snippets:

https://psalm.dev/r/f3e7bae361
<?php

class NoopFilter extends \php_user_filter
{
    /**
     * @param resource $in
     * @param resource $out
     * @param int $consumed
	 */     
    public function filter($in, $out, &$consumed, bool $closing): int
    {
        return PSFS_PASS_ON;
    }
}
Psalm output (using commit 4b2c698):

ERROR: ParamNameMismatch - 10:40 - Argument 3 of NoopFilter::filter has wrong name $consumed, expecting $rw_consumed as defined by php_user_filter::filter

@weirdan
Copy link
Collaborator

weirdan commented Feb 6, 2024

Also affects methods/functions called with named arguments: https://psalm.dev/r/093960fb7a

Copy link

I found these snippets:

https://psalm.dev/r/093960fb7a
<?php
function s(SQLite3Stmt $s): void {
    $v = null;
    $s->bindParam(
        param: 1,
        var: $v,
    );
}

function f(Collator $c): void {
    collator_sort(object: $c, array: [123]);
}
Psalm output (using commit 4b2c698):

ERROR: InvalidNamedArgument - 6:9 - Parameter $var does not exist on function SQLite3Stmt::bindParam

ERROR: TooFewArguments - 4:9 - Too few arguments for SQLite3Stmt::bindParam - expecting rw_var to be passed

ERROR: InvalidNamedArgument - 11:31 - Parameter $array does not exist on function collator_sort

ERROR: TooFewArguments - 11:5 - Too few arguments for collator_sort - expecting rw_array to be passed

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

Successfully merging a pull request may close this issue.

2 participants