PHP allows default values for parameters, even if later parameters do not have default values (it does not using those default values while calling functions though). This diff adds support for that, by dropping the default values of arguments before the last non-optional argument.
- Group Reviewers
- R52:4b10347f367c: Allow optional parameters before non-optional ones in PHP
This looks a bit like a hack.
And it also introduces a regression for e.g.:
Maybe this issue should be addresses at the DUChain-level in kdevplatform? You can probably add a addEmptyDefaultParameter() method in FunctionDefinition in kdevplatform.
Then here (pseudo-algo), do two passes over the param list:
(Or some similar approach..., I don't know the exact DUChain API of the top of my head)
The example you provide still works for me. Maybe you meant function foo($a = 1, $b)? That did not work previously either, since it would show the following signature: [returntype] foo($a, $b = 1). But that would be useful to show, indeed.
In a way, this code already does two passes, to record how many optional/non-optional arguments there are, but I see what you mean. The DUChain code now assumes that any default argument appears at the end of the argument list (and does not store anything for earlier arguments), which is why I chose this approach. I'll check if changing that behaviour is not too difficult.
Works for me. Did you use it with the commit on kdevelop.git? It did not work without that, for me. Also, you might need to clear the cache, otherwise the old (incorrect) behaviour is still stored in the cache.