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.
Details
- Reviewers
kfunk - Group Reviewers
KDevelop - Commits
- R52:4b10347f367c: Allow optional parameters before non-optional ones in PHP
Diff Detail
- Repository
- R52 KDevelop: PHP Support
- Branch
- default_values_allowed_before_required_values
- Lint
No Linters Available - Unit
No Unit Test Coverage
duchain/builders/declarationbuilder.cpp | ||
---|---|---|
754 | 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.
Change approach to default arguments before non-default arguments
This approach just adds default arguments for all arguments, but "empty" default arguments will not be displayed (when combined with D7031)
function foo($a, $b = false, $c) {}
Should work?
Now it says that $c should have a default...
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.