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:37] – tandre | rfc:readline_interactive_shell_result_function [2021/01/16 20:50] – tandre | ||
---|---|---|---|
Line 9: | Line 9: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | Many other REPLs (Read-Eval-Print Loops) that I'm familiar with print a (possibly truncated) representation of the result of expressions, | + | Many REPLs (Read-Eval-Print Loops) |
It would be useful to allow users to extend the functionality of the default interactive php shell ('' | It would be useful to allow users to extend the functionality of the default interactive php shell ('' | ||
Prior to this RFC, there was no way to extend the interactive php shell in this way. | Prior to this RFC, there was no way to extend the interactive php shell in this way. | ||
Line 19: | Line 19: | ||
===== 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 94: | ||
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 122: | ||
</ | </ | ||
- | A new system ini boolean setting '' | + | A new system ini boolean setting '' |
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 70: | Line 141: | ||
===== 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 163: | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
+ | |||
+ | Voting starts on 2021-01-03 and ends 2021-01-17. | ||
+ | |||
Yes/No, requiring 2/3 majority | Yes/No, requiring 2/3 majority | ||
Line 103: | Line 171: | ||
* https:// | * https:// | ||
+ | * https:// |
rfc/readline_interactive_shell_result_function.txt · Last modified: 2021/02/03 00:39 by tandre