Hi internals,
> - Add a hook to `readline` such as
> `readline_set_php_result_handler_callback(function(mixed $result, string
> $snippet){...})`
> that can be used to create a user-defined function to print/process the
> result of expressions.
> (Create a clone of `zend_eval_stringl` to support that)
> (The result value would instead be freed after the callback was called)
>
> Many other REPLs (Read-Eval-Print Loops) that I'm familiar with print a
>representation of the result of expressions, but PHP doesn't.
I've added this in https://github.com/php/php-src/pull/5962 .
I plan to add a system ini setting that can be used to permanently disable this
silently (enabled by default in all environments/example configs)
This will be callable if `readline` is installed, whether or not the shell is
interactive or the SAPI is CLI.
- e.g. `cli.allow_interactive_shell_result_function=1` would be the default.
Other existing settings were
https://www.php.net/manual/en/readline.configuration.php
- A buggy handler closure might interfere with people trying to debug issues,
which is why the ini setting is proposed.
```
readline_interactive_shell_result_function(
function (string $code, $result) {
// echo "Result of: " . trim($code) . "\n";
echo json_encode($result) . "\n"; // or var_dump(), etc.
});
```
1. Are there objections to adding this in 8.1 (after adding the described ini
setting)?
2. Thoughts on the name? readline_interactive_shell_result_handler_function
probably makes more sense.
https://www.php.net/manual/en/function.readline-completion-function.php
does something similar.
The unit tests give an example of how this could be used.
https://github.com/php/php-src/pull/5962/files#diff-153ee3f384d333904c5000033bee9803
Thanks,
- Tyson
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php