From 63dbc3ada3eb3cbc945d9eea4245f2bd75a9c5dd Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 18 Mar 2026 09:33:18 +0100 Subject: [PATCH] Ensure `$assoc_args` can be used in `eval` --- features/eval.feature | 16 ++++++++++++++++ src/Eval_Command.php | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/features/eval.feature b/features/eval.feature index ba4f2f29..d2fae1e0 100644 --- a/features/eval.feature +++ b/features/eval.feature @@ -38,6 +38,22 @@ Feature: Evaluating PHP code and files. #! """ + Scenario: Has access to associative args + Given a WP installation + And a wp-cli.yml file: + """ + eval: + foo: bar + post list: + format: count + """ + + When I run `wp eval 'echo json_encode( $assoc_args );'` + Then STDOUT should be JSON containing: + """ + {"foo": "bar"} + """ + Scenario: Eval without WordPress install Given an empty directory diff --git a/src/Eval_Command.php b/src/Eval_Command.php index 1c94a853..9f09371a 100644 --- a/src/Eval_Command.php +++ b/src/Eval_Command.php @@ -39,7 +39,8 @@ class Eval_Command extends WP_CLI_Command { */ public function __invoke( $args, $assoc_args ) { - $execute_closure = function () use ( $args ) { + // @phpstan-ignore closure.unusedUse + $execute_closure = function () use ( $args, $assoc_args ) { eval( $args[0] ); };