Skip to content

fix: return an empty string when readline() reaches end-of-file - #10542

Merged
paulbalandan merged 1 commit into
codeigniter4:developfrom
paulbalandan:readline-eof
Sep 15, 2026
Merged

paulbalandan merged 1 commit into
codeigniter4:developfrom
paulbalandan:readline-eof

Conversation

@paulbalandan

Copy link
Copy Markdown
Member

Description

readline() returns false when STDIN reaches end-of-file (e.g., the user presses Ctrl+D at a prompt). InputOutput::input() returned that value directly, so under declare(strict_types=1) it threw:

TypeError: CodeIgniter\CLI\InputOutput::input(): Return value must be of type string, false returned in system/CLI/InputOutput.php:50

The fgets() path used when the readline extension is unavailable already maps EOF to ''. This does the same for readline(), so both paths behave identically.

Before:

$ php spark make:controller
Controller class name : ^D
TypeError: CodeIgniter\CLI\InputOutput::input(): Return value must be of type string, false returned

After:

$ php spark make:controller
Controller class name : ^D

The prompt is re-asked or the empty value is returned, exactly as it does today without readline.

readline() cannot be exercised under PHPUnit (the branch is skipped in the testing environment and is @codeCoverageIgnored), so this was verified manually through a pty with expect on macOS libedit.

Checklist:

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

@paulbalandan paulbalandan added the bug Verified issues on the current code behavior or pull requests that will fix them label Sep 12, 2026
@paulbalandan
paulbalandan merged commit 39a0d2f into codeigniter4:develop Sep 15, 2026
59 checks passed
@paulbalandan
paulbalandan deleted the readline-eof branch September 15, 2026 06:49
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.

3 participants