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

Add php2cpg local creation and ClosureRefEdge passes #2782

Merged
merged 5 commits into from
May 31, 2023

Conversation

johannescoetzee
Copy link
Contributor

@johannescoetzee johannescoetzee commented May 30, 2023

Since PHP doesn't require variable declarations, php2cpg would create a Local node on the first use of a new identifier in scope and add a ref edge from the identifier to the local. This approach works well if the identifier in question is added to the CPG, but this isn't always the case. This led to a situation where identifier nodes are added to the CPG (due to the ref edge being added), but not to the AST, leaving them without AST parents.

This PR removes most Local creation from the AstCreator and creates them in a follow-up pass instead. This also means that locals captured by closures must be referenced separately, since the locals being referenced may not exist yet, so the ClosureRefPass adds these.

Resolves #2732

johannescoetzee and others added 2 commits May 31, 2023 09:52
…sses/ClosureRefPass.scala

Co-authored-by: maltek <1694194+maltek@users.noreply.github.com>
@johannescoetzee johannescoetzee merged commit b20411e into master May 31, 2023
5 checks passed
@johannescoetzee johannescoetzee deleted the johannes/php-locals-pass branch May 31, 2023 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] php2cpg: identifiers missing in AST for static method calls and foreach
2 participants