-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
follow value of variable in php script #558
Comments
I use this approach to get property uses in code: $propertyAssignNodes = $this->betterNodeFinder->find([$classNode], function (Node $node) use (
$propertyName
): bool {
if ($node instanceof Assign) {
if ($node->var instanceof PropertyFetch) {
// is property match
return $this->isName($node->var, $propertyName);
}
}
return false;
}); Basically use native What exactly is your goal? Similar analysis does PHPStan and Rector builds on top of that. |
Hello and Thanks! sorry but i didnt get it to work ... maybe you can give an example - thanks a lot! |
What is your goal actually? There might be a better solution. |
ok - here an example:
|
I see. So your goal is to get value of |
yes thats it 👍 |
I tried Rector + PHPStan to resolve the value, but unfortunatelly PHPStan is not capable to analyze the value. Here is code I used: In that way, you'd have to write own NodeScopeResolver - https://github.com/phpstan/phpstan/blob/master/src/Analyser/NodeScopeResolver.php, or extend it. |
What is your ultimate goal to do with the value? |
hey thanks a lot - but how to ge a node from the code? Thanks! |
I started with Documentation: https://github.com/nikic/PHP-Parser/blob/master/doc/2_Usage_of_basic_components.markdown#node-traversation I go through one-change example in this post: How to change PHP code with Abstract Syntax Tree |
okay - i see - but i get the following error:
maybe you can help me a last time - thx a lot! |
Open issue at Rector with full code, so we don't spam here |
ok - sorry ill do that ;) |
Closing this as out of scope for this library. Other libraries provide support for this on top of this one, e.g. various static analyzers. https://github.com/ircmaxell/php-cfg is also worth mentioning, which tracks variable assignments in SSA form. |
Hi, i just want to ask if its possible to follow a variable through a php script?
For example:
$val = "test"; $val2 = $val; echo $val2;
I just found the traverse - but how can i do that exactly?
I could do this with regex - but i want to know if its working with the php parser too?
Thanks and Nice Time!
The text was updated successfully, but these errors were encountered: