Skip to content

Add PHP 8.0 named parameters support#264

Open
BrianHenryIE wants to merge 6 commits into10up:trunkfrom
BrianHenryIE:named-parameters
Open

Add PHP 8.0 named parameters support#264
BrianHenryIE wants to merge 6 commits into10up:trunkfrom
BrianHenryIE:named-parameters

Conversation

@BrianHenryIE
Copy link
Contributor

Summary

Add support for using PHP 8.0 named parameters.

Closes:

No issue opened.

Details

Trying to call a mocked function like:

$value = get_transient(
    transient: 'my-transient-name'
);

results in:

Error : Unknown named parameter $transient

This now works:

WP_Mock::userFunction('get_transient', [
    'times'  => 1,
    'args'   => [
        'transient' => 'my-transient-name',
    ],
    'return' => 'the-mocked-transient-value',
]);

The changes use the args array's keys as the parameter names in the mocked function.

NB: this does not work:

WP_Mock::userFunction('get_transient')->once()->with(['transient' => 'my-transient-name'])->andReturn('the-mocked-transient-value');

The Functions::createFunction() has already been called and the function skeleton built and eval()'d, which is where the parameter names must be added.

Contributor checklist

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly
  • I have added tests to cover changes introduced by this pull request
  • All new and existing tests pass

Testing

One test added which skips if the PHP version is too low.

Reviewer checklist

  • Code changes review
  • Documentation changes review
  • Unit tests pass
  • Static analysis passes

@coveralls
Copy link

coveralls commented Jan 16, 2026

Coverage Status

coverage: 66.451% (+0.3%) from 66.142%
when pulling 8fe92eb on BrianHenryIE:named-parameters
into 446ea70 on 10up:trunk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants