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

PHP: Support for matching types in function parameters #4589

Closed
idawson-gl opened this issue Feb 1, 2022 · 1 comment
Closed

PHP: Support for matching types in function parameters #4589

idawson-gl opened this issue Feb 1, 2022 · 1 comment
Labels
alpha Relates to an experimental feature feature:matching lang:php priority:low user:external requested by someone outside of r2c

Comments

@idawson-gl
Copy link

Right now it's not possible to match types defined in function parameters. This makes it impossible to match functions or methods that are defined with type information.

Example here: https://semgrep.dev/s/idawson-gl:findmethod

It would be excellent if we were able to match on types, or use ellipsis to ignore them.

The only way to currently match a function like the one above is to have a rule that matches the variable name, which.. is not ideal.

rules:
- id: Test
  patterns:
    - pattern: public function someMethod($X) { ... }
    - metavariable-regex:
        metavariable: $X
        regex: (.*var.*)  
  message: someMethod with var
  languages: [php]
  severity: INFO

Interestingly, this is also an issue for classes that extend other classes (again seems to be a type propagation issue). The difference is I can actually get it to match (again using metavariable-regex):

rules:
- id: Test
  patterns:
    - pattern: |
        class $CLASS extends $X { ... }
    - metavariable-regex:
        metavariable: $X
        regex: (\\SomePkg\\SomeBase)    
  message: someMethod with var
  languages: [php]
  severity: INFO
@aryx aryx added lang:php priority:low user:external requested by someone outside of r2c labels Feb 2, 2022
@IagoAbal IagoAbal added alpha Relates to an experimental feature feature:matching labels Feb 3, 2022
@aryx
Copy link
Collaborator

aryx commented May 31, 2022

This https://semgrep.dev/s/idawson-gl:findmethod works now

@aryx aryx closed this as completed May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
alpha Relates to an experimental feature feature:matching lang:php priority:low user:external requested by someone outside of r2c
Development

No branches or pull requests

3 participants