fuel/core

PHP8 OR LATER

daisuke1101 opened this issue · 6 comments

Hello,
I am an END-USER of FuelPHP 1.9.

I am sorry that,in
PHP8 OR LATER,
Undefined constant "Fuel\Core\STDERR" in
fuel/core/classes/cli.php on line 94

  static::$STDERR = STDERR;
  static::$STDOUT = STDOUT;

m(__)m

The STDOUT and STDERR constants are only defined in the cli version of php, the Cli class is not meant to be used bu the cgi version.

How are you using this exactly?

I am using FuelPHP 1.9/dev in
PHP 8.0.27, FPM/FastCGI mode.

The STDOUT and STDERR constants are only defined in the cli version of php, the Cli class is not meant to be used bu the cgi version.


I APOLOGIZE for the IGNORANCE.

In the function in MODEL or CONTROLLER,
When RUNNING TASKS,
I TOGGLED cli mode BETWEEN FALSE and TRUE.

        // Loading oil Package
        \Package::load('oil');

        // Environment Setting
        // Assign DEFAULT cli mode flag to $bf
        $bf = \Fuel::$is_cli;
        // TOGGLE cli mode TRUE
        \Fuel::$is_cli = true;
        // Define Count of Arguments
        $_SERVER['argc'] = 1;

        // Run Task
        // FORMAT: \Oil\Refine::run('[TASK File Name]:[Function]', array([Arguments]));
        \Oil\Refine::run('hoge:fuga', array($arg));
        // TOGGLE cli mode DEFAULT(= FALSE)
        \Fuel::$is_cli = $bf;

For your reference(JAPANESE SITE,CAUTION!),

https://qiita.com/goosys/items/d9dff999db4239f75dc1

Which php binary do you use? Check the output of php -v. You should see

[wanwizard@alfred] $ php -v
PHP 8.2.5 (cli) (built: Apr 11 2023 16:16:23) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.5, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.5, Copyright (c), by Zend Technologies
    with Xdebug v3.2.1, Copyright (c) 2002-2023, by Derick Rethans

indicating the cli binary is used.

p.s. changing \Fuel::$is_cli doesn't magically enable CLI, it is a 'read-only' variable indicating whether or not you are runing in CLI mode.

You should not run tasks from a web request, which I suspect is what you are doing, they have not been designed to work that way.

If you insist, you can work around this issue by adding this to your code:

if(!defined('STDIN'))  define('STDIN',  fopen('php://stdin',  'rb'));
if(!defined('STDOUT')) define('STDOUT', fopen('php://stdout', 'wb'));
if(!defined('STDERR')) define('STDERR', fopen('php://stderr', 'wb'));

Which php binary do you use? Check the output of php -v. You should see

[wanwizard@alfred] $ php -v
PHP 8.2.5 (cli) (built: Apr 11 2023 16:16:23) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.5, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.5, Copyright (c), by Zend Technologies
    with Xdebug v3.2.1, Copyright (c) 2002-2023, by Derick Rethans

indicating the cli binary is used.

My ENVIRONMENT IS

$ php -v
PHP 8.0.27 (cli) (built: Jan  3 2023 16:17:26) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.27, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.27, Copyright (c), by Zend Technologies

p.s. changing \Fuel::$is_cli doesn't magically enable CLI, it is a 'read-only' variable indicating whether or not you are runing in CLI mode.

You should not run tasks from a web request, which I suspect is what you are doing, they have not been designed to work that way.

THANK YOU FOR YOUR ADVICE.