Search code examples
phpwindowscommand-line-interfacephp-extension

PHP 7.1+ Windows readline extension not all functions exist


One of the improvements in PHP7.1 is that in Windows the readline extension is available out of the box. I'm having trouble using all of the functions though, as they don't all exist. The following code:

$functions = [
    'readline_add_history',
    'readline_callback_handler_install',
    'readline_callback_handler_remove',
    'readline_callback_read_char',
    'readline_clear_history',
    'readline_completion_function',
    'readline_info',
    'readline_list_history',
    'readline_on_new_line',
    'readline_read_history',
    'readline_redisplay',
    'readline_write_history',
    'readline'
];
foreach($functions as $function) {
    echo $function . (function_exists($function) ? ' exists' : ' does not exist') . PHP_EOL;
}

...produces the following output:

readline_add_history exists
readline_callback_handler_install does not exist
readline_callback_handler_remove does not exist
readline_callback_read_char does not exist
readline_clear_history exists
readline_completion_function exists
readline_info exists
readline_list_history does not exist
readline_on_new_line does not exist
readline_read_history exists
readline_redisplay does not exist
readline_write_history exists
readline exists

I can't find any reference in the PHP manual that only a subset of the readline extension's functions are available in Windows.

When I call php_info(), I get the following output:

readline

Readline Support enabled

Readline library WinEditLine

Is there some php.ini configuration setting (or CLI argument) that needs to be made in order to make all functions available? Alternately, is there some other way of making functions such as readline_callback_handler_install() available in Windows, or is the extension only half-baked?


Solution

  • For the record

    PHP >= 7.4 to 8.1

    yes:

    • readline_add_history
    • readline_clear_history
    • readline_completion_function
    • readline_info
    • readline_list_history
    • readline_read_history
    • readline_write_history
    • readline

    no:

    • readline_callback_handler_install
    • readline_callback_handler_remove
    • readline_callback_read_char
    • readline_on_new_line
    • readline_redisplay

    readline_list_history was added around during versions 7.2 and 7.3