Find function usages with certain optional parameter specified
Say I have the following function:
function foo($param1, $param2 = null, $param3 = null, $param4 = 'test')
{
// ...
}
Is there a way to find usages of this function where optional parameter "$param3" is specified?
请先登录再写评论。
Hi there,
Use SSR (Structural Search and Replace) functionality: https://www.jetbrains.com/help/phpstorm/structural-search-and-replace.html
Also (recent similar question on SO): https://stackoverflow.com/a/62544002/783119
Thank you for fast and clear answer!
This was my specific use case as well. And since there didn't appear to be any obvious examples of searching for a function with an optional parameter provided, this is an example of how to accomplish what you asked (which helped me):
First time using it, so it's important to just ensure that each parameter name differs. One minor issue with this approach however is that if, for example, the calls to `foo` happen to have booleans or some other common value reused multiple times in the parameter list, it will get skipped (since once $a$ matches a value, it expects $b$ to then be not equal to $a$).
The only way around that which I've seen was to then click on each variable in the template, click "Add Filter" on the right, then select text and then plug in ".*" (regex to match everything). See below for an example.