简体   繁体   中英

PHP interactive shell, auto echo and a new line

Greetings fellow programmers!

Is there a way to get PHPs interactive shell, php -a , to behave more like Rails console or the console in Chrome? I have looked through the flags for the php-command, but no dice.

What I get:

php > $a = 0;
php > $a;
php > echo $a;
0php > 

What I want

php > $a = 0;
0
php > $a;
0
php > echo $a;
0
php > 

You have at least three possibilities to solve this problem:

  1. Manually add PHP_EOL to all your echo : echo $a . PHP_EOL echo $a . PHP_EOL ;
  2. Introduce your idea on official php ideas wiki and wait until someone implement it.
  3. Learn php git workflow for external contributors , create needed functionality and send the patch to developers.

As of 2022, PsySH seems to be a modern maintained valid solution for the asked question:

Psy Shell v0.11.5 (PHP 7.4.3 — cli) by Justin Hileman
>>> $a = 0
=> 0

>>> $a
=> 0

>>> echo $a
0⏎

All the more:

  • as one can see above, semi-colon is optional
  • the output is slightly different for an echo expression
  • a single eval statement dropped anywhere in a code base is enough to set a breakpoint powered by this REPL

Check into Boris , described as "PHP's missing REPL ". echo and print still require manual newlines, but naked expressions are evaluated and pretty-printed:

[1] boris> $a = 0;
// 0
[2] boris> $a;
// 0
[3] boris> echo $a;
0[4] boris>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM