Skip to content

Bug: Constant STDOUT already defined  #7047

Closed
@jozefrebjak

Description

@jozefrebjak

PHP Version

8.1

CodeIgniter4 Version

4.2.11

CodeIgniter4 Installation Method

Composer (as dependency to an existing project)

Which operating systems have you tested for this bug?

macOS

Which server did you use?

cli

Database

MariaDB 10.9.3

What happened?

When I trying to call command from Controller with params I'm getting

ErrorException
Constant STDOUT already defined

Here is the screenshot:

CleanShot 2023-01-03 at 13 05 49@2x

Steps to Reproduce

Controller method includes line:

command('command:command')

Command includes line:

$isId = (bool) CLI::getOption('i');

where it's failing.

Expected Output

Execute command.

Anything else?

I tried to look at method in vendor/codeigniter4/framework/system/CLI/CLI.php and what I found is when I delete define('STDOUT', 'php://output'); // @codeCoverageIgnore then it's working as expected.

Do we need to define it in else statement ? Or I'm calling command wrong.

/**
     * Static "constructor".
     */
    public static function init()
    {
        if (is_cli()) {
            // Readline is an extension for PHP that makes interactivity with PHP
            // much more bash-like.
            // http://www.php.net/manual/en/readline.installation.php
            static::$readline_support = extension_loaded('readline');

            // clear segments & options to keep testing clean
            static::$segments = [];
            static::$options  = [];

            // Check our stream resource for color support
            static::$isColored = static::hasColorSupport(STDOUT);

            static::parseCommandLine();

            static::$initialized = true;
        } else {
            // If the command is being called from a controller
            // we need to define STDOUT ourselves
-          define('STDOUT', 'php://output'); // @codeCoverageIgnore
        }
    }

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