Skip to content

fix: avoid undefined STDERR and STDIN outside the CLI - #10605

Merged
paulbalandan merged 1 commit into
codeigniter4:developfrom
paulbalandan:cli-streams-outside-cli
Oct 9, 2026
Merged

paulbalandan merged 1 commit into
codeigniter4:developfrom
paulbalandan:cli-streams-outside-cli

Conversation

@paulbalandan

Copy link
Copy Markdown
Member

Description

Fixes #5006

PHP defines STDIN, STDOUT and STDERR only in the CLI SAPI, and CLI::init() provides a stand-in for STDOUT alone. So CLI::error() ends a web request with Undefined constant "CodeIgniter\CLI\STDERR" when a command runs through command() in a controller. Outside the CLI it now writes through STDOUT, so command() returns the message like any other output. CLI::clearScreen() on Windows and SignalTrait::getProcessState() had the same problem, and both are guarded the same way.

The fix checks is_cli() rather than defining the missing constants, because defined('STDIN') is a common way to detect the CLI and defining it in web requests would break those checks.

Only CLI::error() has a regression test. Under PHPUnit STDIN is always defined, and the clearScreen() path is Windows-only.

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

@carson-codeigniter4 carson-codeigniter4 Bot added the bug Verified issues on the current code behavior or pull requests that will fix them label Oct 9, 2026
@paulbalandan
paulbalandan merged commit 12a9bb5 into codeigniter4:develop Oct 9, 2026
61 checks passed
@paulbalandan
paulbalandan deleted the cli-streams-outside-cli branch October 9, 2026 12:42
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.

Bug: Undefined constant CodeIgniter\CLI\STDERR

2 participants