Skip to content

Bug: Undefined constant CodeIgniter\CLI\STDERR #5006

Closed

Description

@tonynamy

PHP Version

8.5

CodeIgniter4 Version

4.7.4

CodeIgniter4 Installation Method

Git

Which operating systems have you tested for this bug?

macOS, Linux

Which server did you use?

cli-server (PHP built-in webserver)

Environment

development

Database

No response

What happened?

Running a command from a controller through command() ends in a fatal error when the command reports an error with CLI::error():

Error: Undefined constant "CodeIgniter\CLI\STDERR"

PHP defines STDIN, STDOUT and STDERR only in the CLI SAPI. Outside the CLI, CLI::init() defines a stand-in for STDOUT (php://output) but not for STDERR, and CLI::error() references STDERR both for its color check and for the write itself.

Steps to Reproduce

  1. Add a route to a controller method that runs a command reporting an error, for example an unknown command name:

    public function index(): string
    {
        return (string) command('no:such-command');
    }
  2. Serve the app with a web SAPI (php spark serve, Apache with mod_php, or PHP-FPM).

  3. Request the route.

Expected Output

command() returns the error message as part of the command's output, the same way it returns output from CLI::write(), instead of the request ending in a fatal error.

Anything else?

Originally reported on CodeIgniter 4.1.3 with PHP 8.0.8, Apache 2.4.29 and Ubuntu 18.04.5, using a custom command that calls CLI::error(). The reporter worked around it by overriding CLI::error() to write through STDOUT when is_cli() is false.

Still reproducible on develop (b86f337). The same class of problem affects CLI::clearScreen() on Windows, which probes the STDOUT stand-in string for VT100 support, and SignalTrait::getProcessState(), which calls posix_isatty(STDIN).

Activity

  1. added
    bugVerified issues on the current code behavior or pull requests that will fix them
    on Aug 17, 2021
  2. MGatner commented on Aug 17, 2021

    @MGatner
    Member

    I think @paulbalandan already fixed this on 4.2, perhaps?

  3. changed the title [-]Bug: [/-] [+]Bug: Undefined constant CodeIgniter\CLI\STDERR[/+] on Aug 17, 2021
  4. paulbalandan commented on Aug 17, 2021

    @paulbalandan
    Member

    Yes, fixed in 4.2

  5. changed the title [-]Bug: Undefined constant CodeIgniter\CLI\STDERR[/-] [+]Bug: Undefined constant `CodeIgniter\CLI\STDERR`[/+] on Oct 9, 2026
  6. paulbalandan commented on Oct 9, 2026

    @paulbalandan
    Member

    Apparently, this issue was not fixed in 4.2 🤦‍♂️ @tonynamy my apologies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions