Add PHP 8.0 named parameters support - #264
BrianHenryIE wants to merge 11 commits into
Conversation
AndrewJDawes
left a comment
There was a problem hiding this comment.
Hey, @BrianHenryIE !
It looks like we are anticipating the possibility of mixed array keys - some integers, some not.
And in response, we are taking an all-or-nothing approach where if any array key is an integer, we bail and do not define the function with any named params
What if we instead dynamically filtered the final $functionNamedParameters to only include array keys which are not integers?
Otherwise, looks good to me. I would be interested in seeing this merged!
Co-authored-by: Andrew Dawes <53574062+AndrewJDawes@users.noreply.github.com>
|
@AndrewJDawes Excellent point, in fact a mix of unnamed and named is valid once the positional parameters come before the named parameters. I added two tests – the case of mixed positional and named, and out-of-order named – and merged your suggestion. I made an extra change to include positional args as |
Summary
Add support for using PHP 8.0 named parameters.
Closes:
No issue opened.
Details
Trying to call a mocked function like:
results in:
This now works:
The changes use the
argsarray's keys as the parameter names in the mocked function.NB: this does not work:
The
Functions::createFunction()has already been called and the function skeleton built andeval()'d, which is where the parameter names must be added.Contributor checklist
Testing
One test added which skips if the PHP version is too low.
Reviewer checklist