rfc:readline_interactive_shell_result_function_straw_poll
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:readline_interactive_shell_result_function_straw_poll [2021/01/06 02:50] – created tandre | rfc:readline_interactive_shell_result_function_straw_poll [2021/01/06 03:23] – tandre | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Straw poll: Interest in configurable callback to dump results of expressions in `php -a` ====== | + | ====== Straw poll: Interest in configurable callback to dump results of expressions in '' |
* Version: 0.1 | * Version: 0.1 | ||
* Date: 2021-01-05 | * Date: 2021-01-05 | ||
Line 23: | Line 23: | ||
For the sake of discussion, the following default implementation is proposed. | For the sake of discussion, the following default implementation is proposed. | ||
var_dump() is proposed for arrays and objects because it properly represents references and cyclic data structures. | var_dump() is proposed for arrays and objects because it properly represents references and cyclic data structures. | ||
+ | |||
+ | '' | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
The proposed snippet would be to behave as if this snippet were evaluated before '' | The proposed snippet would be to behave as if this snippet were evaluated before '' | ||
Line 91: | Line 96: | ||
</ | </ | ||
- | ===== Proposed Voting Choices | + | Improvements to the default result expression dumper can be proposed in subsequent RFCs if this ends up being added. |
+ | |||
+ | ===== Discussion ===== | ||
+ | |||
+ | ==== Propose defaults implementations first? ==== | ||
+ | |||
+ | < | ||
+ | by Rowan Tommins: | ||
+ | |||
+ | > I'd planned to propose defaults if this passed. | ||
+ | |||
+ | Then I guess my feedback can be summarised as: propose these default | ||
+ | implementations first, rather than last. Start by improving the | ||
+ | out-of-the-box experience, and then look at what hooks userland tools | ||
+ | might want to customise that (which might involve something " | ||
+ | than replacing the entire output routine). | ||
+ | |||
+ | > Psysh is 2.4MB as a compiled phar release and larger if distributed with library/ | ||
+ | default extension hooks would likely be much smaller. | ||
+ | |||
+ | That was a lot of data when I used to carry floppy disks around in my | ||
+ | school backpack. It sounds pretty reasonable for a feature-rich | ||
+ | command-line tool in 2021. | ||
+ | |||
+ | > Someone learning from the php.net manual or a tutorial with minimal dependencies wouldn' | ||
+ | |||
+ | To be honest, I doubt most users ever come across php -a either, or know | ||
+ | that they need to install ext/ | ||
+ | pretty sure that's not installed by default on Ubuntu, for instance). | ||
+ | |||
+ | I'm supportive of the idea of changing that, but I don't think the RFC | ||
+ | as currently presented particularly helps that cause. | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== Formatting output ==== | ||
+ | < | ||
+ | by Rowan Tommins: | ||
+ | |||
+ | A couple of notes on this: | ||
+ | |||
+ | * The readline-based shell for "php -a" was added in PHP 5.1 | ||
+ | [https:// | ||
+ | __debugInfo not until 5.6 [https:// | ||
+ | * I agree that the existing debug outputs are quite verbose, but I don' | ||
+ | think that's a problem unique to the REPL. '' | ||
+ | to render valid PHP code, but '' | ||
+ | should represent objects more compactly. | ||
+ | * That compact representation of a Point ('' | ||
+ | everywhere anyone wanted debug output. It would also be possible to | ||
+ | build it on top of the existing functionality (key-value pairs from | ||
+ | '' | ||
+ | * Allowing objects to overload the output seems much preferable to the | ||
+ | formatting function having to know all the special cases, so I'm not | ||
+ | convinced of the need to hook the entire output for the shell. | ||
+ | * I can't find any references off-hand, but I'm pretty sure popular | ||
+ | REPLs in other languages take that approach: use existing | ||
+ | pretty-printing mechanisms from the language, which in turn can be | ||
+ | overloaded by individual types / classes. | ||
+ | </ | ||
+ | |||
+ | Adding a pretty-printing alternative to '' | ||
+ | ( e.g. '' | ||
+ | |||
+ | ==== Exposing the ability to handle input and recover from fatal errors in interactive shells ==== | ||
+ | |||
+ | < | ||
+ | by Rowan Tommins: | ||
+ | |||
+ | If all the code using these hooks is going to be distributed as userland | ||
+ | code anyway, then they' | ||
+ | |||
+ | It feels like we need to go in one of two directions: | ||
+ | |||
+ | a) Build a full-featured official REPL with all of these improvements | ||
+ | completely implemented out of the box. Limited extension hooks might | ||
+ | still be desirable to build custom versions for frameworks etc, but they | ||
+ | could be more targeted - for custom input, it could be " | ||
+ | meta-command"; | ||
+ | class level. | ||
+ | |||
+ | b) Expose the magic behaviour needed for something like PsySh to do | ||
+ | everything '' | ||
+ | the only mentioned requirement is a special form of eval() that swallows | ||
+ | fatal errors. | ||
+ | |||
+ | My feeling is that the current mood of the community favours (b) rather | ||
+ | than (a); the most obvious example is that PHP used to bundle a PEAR | ||
+ | executable, but Composer remains an entirely external project. Is there | ||
+ | a reason not to aim for the same "de facto standard" | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | by Tyson Andre: | ||
+ | |||
+ | Compared to psysh, the main distinguishing feature is definitely the ability to detect/ | ||
+ | I don't think it should be exposed to regular processes or web servers, though, due to possible memory corruption or leaks after zend_error_noreturn (e.g. class inheritance errors after autoloading), | ||
+ | |||
+ | * It would possibly be an improvement to throw an error instead of causing a fatal error for common mistakes in interactive | ||
+ | shell sessions such as duplicate functions/ | ||
+ | |||
+ | |||
+ | Integrating userland shells like '' | ||
+ | Two hooks may help with enabling that approach, which can be added in auto_prepend_file | ||
+ | |||
+ | * A hook to call a callback instead of printing "php >" and C readline reading stdin. | ||
+ | e.g. '' | ||
+ | * Adding a hook to call a function every time an uncatchable fatal error was encountered, | ||
+ | e.g. '' | ||
+ | </ | ||
+ | |||
+ | ===== Vote ===== | ||
- | This is a multiple choice poll, fill out any acceptable options. | + | **This is a multiple choice poll,** fill out any acceptable options. |
- | The proposed default uses var_export for scalars, nothing for | + | The proposed default uses var_export for scalars, nothing for null, and var_dump for objects/ |
<doodle title=" | <doodle title=" | ||
- | * Support overriding | + | * Support overriding |
- | * Support overriding | + | * Support overriding |
- | | + | |
* Opposed to previous options | * Opposed to previous options | ||
* Opposed to adding this | * Opposed to adding this | ||
Line 119: | Line 235: | ||
===== References ===== | ===== References ===== | ||
- | https:// | ||
+ | * https:// | ||
+ | * https:// |
rfc/readline_interactive_shell_result_function_straw_poll.txt · Last modified: 2021/01/16 20:25 by tandre