Skip to content

fix: write the prompt to STDOUT before readline() on Windows - #10534

Open
michalsn wants to merge 1 commit into
codeigniter4:developfrom
michalsn:fix/readline-wineditline
Open

fix: write the prompt to STDOUT before readline() on Windows#10534
michalsn wants to merge 1 commit into
codeigniter4:developfrom
michalsn:fix/readline-wineditline

Conversation

@michalsn

@michalsn michalsn commented Sep 8, 2026

Copy link
Copy Markdown
Member

Description
This PR is a follow-up to #10507. On Windows readline_info() never exposes a library_version key: php-src adds it under #ifndef PHP_WIN32 (ext/readline/readline.c), because the extension is built on WinEditLine there instead of GNU readline. readline_info('library_version') therefore returns null on every Windows build with the extension enabled, and under declare(strict_types=1) the new str_contains() call in InputOutput::input() throws:

[TypeError]
str_contains(): Argument #1 ($haystack) must be of type string, null given
at SYSTEMPATH\CLI\InputOutput.php:48

Every spark command that asks a question (e.g. shield:setup, or any generator asked to overwrite a file) crashes on Windows since #10507, whenever the readline extension is enabled (the default in the official builds). Windows with readline disabled is not affected, as input() takes the fgets() path. Reproduced with the official PHP 8.4.25 and 8.0.25 builds.

A plain null guard is not enough: WinEditLine prints ANSI sequences passed in the readline prompt literally, so a coloured default option would render as [[32my[0m, n]:. This PR extracts the prompt decision into InputOutput::readlinePrompt():

Tested interactively on Windows 11 / PHP 8.4.25 with CLI::prompt(), CLI::promptByKey() and a plain prompt: colours render correctly, the typed values come back, and the prompt text stays intact after backspacing past the start of the input (WinEditLine is not affected by the bug #10507 fixed, so the old behaviour is safe there).

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@michalsn michalsn added the bug Verified issues on the current code behavior or pull requests that will fix them label Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Verified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants