diff --git a/features/shell.feature b/features/shell.feature index 6cf104ce..5e9b48f6 100644 --- a/features/shell.feature +++ b/features/shell.feature @@ -78,6 +78,44 @@ Feature: WordPress REPL history: -1: invalid option """ + Scenario: User can define variable named $line + Given a WP install + And a session file: + """ + $line = 'this should work'; + $line; + """ + + When I run `wp shell --basic < session` + Then STDOUT should contain: + """ + => string(16) "this should work" + """ + And STDOUT should contain: + """ + => string(16) "this should work" + """ + + Scenario: User can define variables named $out and $evl + Given a WP install + And a session file: + """ + $out = 'out should work'; + $evl = 'evl should work'; + $out; + $evl; + """ + + When I run `wp shell --basic < session` + Then STDOUT should contain: + """ + => string(15) "out should work" + """ + And STDOUT should contain: + """ + => string(15) "evl should work" + """ + Scenario: Shell with hook parameter Given a WP install And a session file: diff --git a/src/WP_CLI/Shell/REPL.php b/src/WP_CLI/Shell/REPL.php index 9415fc96..f7afc354 100644 --- a/src/WP_CLI/Shell/REPL.php +++ b/src/WP_CLI/Shell/REPL.php @@ -19,38 +19,38 @@ public function __construct( $prompt ) { public function start() { // @phpstan-ignore while.alwaysTrue while ( true ) { - $line = $this->prompt(); + $__repl_input_line = $this->prompt(); - if ( '' === $line ) { + if ( '' === $__repl_input_line ) { continue; } - $line = rtrim( $line, ';' ) . ';'; + $__repl_input_line = rtrim( $__repl_input_line, ';' ) . ';'; - if ( self::starts_with( self::non_expressions(), $line ) ) { + if ( self::starts_with( self::non_expressions(), $__repl_input_line ) ) { ob_start(); // phpcs:ignore Squiz.PHP.Eval.Discouraged -- This is meant to be a REPL, no way to avoid eval. - eval( $line ); - $out = (string) ob_get_clean(); - if ( 0 < strlen( $out ) ) { - $out = rtrim( $out, "\n" ) . "\n"; + eval( $__repl_input_line ); + $__repl_output = (string) ob_get_clean(); + if ( 0 < strlen( $__repl_output ) ) { + $__repl_output = rtrim( $__repl_output, "\n" ) . "\n"; } - fwrite( STDOUT, $out ); + fwrite( STDOUT, $__repl_output ); } else { - if ( ! self::starts_with( 'return', $line ) ) { - $line = 'return ' . $line; + if ( ! self::starts_with( 'return', $__repl_input_line ) ) { + $__repl_input_line = 'return ' . $__repl_input_line; } // Write directly to STDOUT, to sidestep any output buffers created by plugins ob_start(); // phpcs:ignore Squiz.PHP.Eval.Discouraged -- This is meant to be a REPL, no way to avoid eval. - $evl = eval( $line ); - $out = (string) ob_get_clean(); - if ( 0 < strlen( $out ) ) { - echo rtrim( $out, "\n" ) . "\n"; + $__repl_eval_result = eval( $__repl_input_line ); + $__repl_output = (string) ob_get_clean(); + if ( 0 < strlen( $__repl_output ) ) { + echo rtrim( $__repl_output, "\n" ) . "\n"; } echo '=> '; - var_dump( $evl ); + var_dump( $__repl_eval_result ); fwrite( STDOUT, (string) ob_get_clean() ); } }