rfc:readline_interactive_shell_result_function
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:readline_interactive_shell_result_function [2020/12/20 22:38] – tandre | rfc:readline_interactive_shell_result_function [2021/01/16 20:53] – tandre | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== PHP RFC: Configurable callback to dump results of expressions in `php -a` ====== | + | ====== PHP RFC: Dump results of expressions in `php -a` ====== |
* Version: 0.1 | * Version: 0.1 | ||
* Date: 2020-12-19 | * Date: 2020-12-19 | ||
Line 14: | Line 14: | ||
(I've seen https:// | (I've seen https:// | ||
- | Because PHP's interactive shell is written in C, adding new features or bug fixes would require a lot of time getting familiar with | ||
- | C programming, | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | Add a new function '' | + | By default, in '' |
+ | Additionally, | ||
- | Using this, users or applications can configure callables to be run every time a statement containing a single expression such as '' | + | This will dump the results of expressions |
+ | |||
+ | An example of the behavior of the default expression dumper is below: | ||
+ | |||
+ | <code php> | ||
+ | $ php -a | ||
+ | Interactive shell | ||
+ | |||
+ | php > 1+1; | ||
+ | => 2 | ||
+ | php > 0.5 * 2; | ||
+ | => 1.0 | ||
+ | php > namespace\MyClass:: | ||
+ | => ' | ||
+ | php > fn()=> | ||
+ | => object(Closure)# | ||
+ | } | ||
+ | php > $x = [" | ||
+ | => array(2) { | ||
+ | [0]=> | ||
+ | string(3) " | ||
+ | [1]=> | ||
+ | string(3) " | ||
+ | } | ||
+ | php > asort($x); | ||
+ | => true | ||
+ | php > $x; | ||
+ | => array(2) { | ||
+ | [1]=> | ||
+ | string(3) " | ||
+ | [0]=> | ||
+ | string(3) " | ||
+ | } | ||
+ | php > json_encode($x); | ||
+ | => ' | ||
+ | php > unset($x); | ||
+ | php > function do_something() { echo "in do_something()\n"; | ||
+ | php > do_something(); | ||
+ | in do_something() | ||
+ | php > json_decode(' | ||
+ | => object(stdClass)# | ||
+ | [" | ||
+ | string(5) " | ||
+ | } | ||
+ | php > throw new RuntimeException(" | ||
+ | |||
+ | Warning: Uncaught RuntimeException: | ||
+ | Stack trace: | ||
+ | #0 {main} | ||
+ | thrown in php shell code on line 1 | ||
+ | php > printf(" | ||
+ | newline is automatically appended by shell | ||
+ | => 42 | ||
+ | php > printf(" | ||
+ | newline not automatically appended by shell | ||
+ | => 44 | ||
+ | php > { print(" | ||
+ | test | ||
+ | php > | ||
+ | </ | ||
+ | |||
+ | Using the function '' | ||
<code php> | <code php> | ||
Line 32: | Line 92: | ||
php ( echo json_encode($result); | php ( echo json_encode($result); | ||
php ( }); | php ( }); | ||
+ | Saw readline_interactive_shell_result_function( | ||
+ | | ||
+ | echo "Saw " . trim($code) . " | ||
+ | echo json_encode($result); | ||
+ | }); | ||
+ | true | ||
php > 2+2; | php > 2+2; | ||
Saw 2+2; | Saw 2+2; | ||
4 | 4 | ||
+ | php > readline_interactive_shell_result_function(null); | ||
+ | php > 2+2; | ||
+ | php > | ||
</ | </ | ||
Line 51: | Line 120: | ||
</ | </ | ||
- | A new system ini boolean setting '' | + | A new system ini boolean setting '' |
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 70: | Line 139: | ||
===== Future Scope ===== | ===== Future Scope ===== | ||
- | |||
- | ==== Providing a default callback to dump expression results ==== | ||
- | |||
- | This RFC is minimal and does not provide a default implementation for rendering values of expressions (i.e. there is no callback by default). Providing a default is feasible, but there are a variety of choices that could be made (e.g. var_dump vs var_export vs shorter JSON-like equivalents for simple arrays, handling of recursive data structures, truncating output, etc). | ||
- | |||
- | * In order to provide more extensive default handlers for tab completion and rendering of evaluated expressions, | ||
From https:// | From https:// | ||
Line 98: | Line 161: | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
+ | |||
Yes/No, requiring 2/3 majority | Yes/No, requiring 2/3 majority | ||
Line 103: | Line 167: | ||
* https:// | * https:// | ||
+ | * https:// |
rfc/readline_interactive_shell_result_function.txt · Last modified: 2021/02/03 00:39 by tandre