[RFC] Configurable callback to dump results of expressions in `php -a`
| From: | tyson andre | Date: | Sun, 20 Dec 2020 22:36:38 +0000 |
| Subject: | [RFC] Configurable callback to dump results of expressions in `php -a` | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-112568@lists.php.net to get a copy of this message | ||
Hi internals,
I've created a new RFC https://wiki.php.net/rfc/readline_interactive_shell_result_function
adding a way to configure a callback to be called to dump the value of single-expression statements
from
php -a
(and an ini setting that can be disabled to prevent that callback from being called).
Many REPLs (Read-Eval-Print Loops) for other programming languages that I'm familiar with
print a (possibly truncated) representation of the result of expressions, but PHP doesn't.
It would be useful to allow users to extend the functionality of the default interactive php shell
(php -a),
possibly with auto_prepend_file or through use of command wrappers/aliases, or after loading the
shell.
Prior to this RFC, there was no way to extend the interactive php shell in this way.
(I've seen https://github.com/bobthecow/psysh
mentioned as an alternative for php -a while investigating this,
but that's a shell written from scratch, and doesn't have some functionality from php -a
such as tolerance of fatal errors)
Because PHP's interactive shell is written in C, adding new features or bug fixes is
inconvenient - it would require a lot
of time getting familiar with C programming, PHP's internals and memory management,
and with PHP's internal C ast representation.
It would be easier and more accessible to extend PHP's interactive shell through code written
in PHP rather than code written in C.
This was among the proposed enhancements I brought up in https://externals.io/message/111073 .
An earlier version of the implementation was also created months ago - https://github.com/php/php-src/pull/5962
Thanks,
- Tyson