Cara menggunakan php undefined constant stderr

  • Toximik
    Newbie

  • Posts: 1
    Threads: 1
    Joined: Jul 2021

    Reputation: 0


Hi, 
i have just installed fresh CI4 using composer (composer create-project codeigniter4/appstarter test) and set baseURL i get this error:

Code:

Fatal error: Uncaught ErrorException: Use of undefined constant STDOUT - assumed 'STDOUT' (this will throw an Error in a future version of PHP) in /var/www/html/test/vendor/codeigniter4/framework/system/CLI/CLI.php:162 Stack trace: #0 /var/www/html/test/vendor/codeigniter4/framework/system/CLI/CLI.php(162): CodeIgniter\Debug\Exceptions->errorHandler(2, 'Use of undefine...', '/var/www/html/t...', 162, Array) #1 /var/www/html/test/vendor/codeigniter4/framework/system/CLI/CLI.php(1184): CodeIgniter\CLI\CLI::init() #2 /var/www/html/test/vendor/codeigniter4/framework/system/Autoloader/Autoloader.php(300): include_once('/var/www/html/t...') #3 /var/www/html/test/vendor/codeigniter4/framework/system/Autoloader/Autoloader.php(273): CodeIgniter\Autoloader\Autoloader->includeFile('/var/www/html/t...') #4 /var/www/html/test/vendor/codeigniter4/framework/system/Autoloader/Autoloader.php(247): CodeIgniter\Autoloader\Autoloader->loadInNamespace('CodeIgniter\\CLI...') #5 [internal function]: CodeIgniter\Autoloader\Autoloader->loadClass( in /var/www/html/test/vendor/codeigniter4/framework/system/CLI/CLI.php on line 162

Fatal error: Uncaught ErrorException: Use of undefined constant STDOUT - assumed 'STDOUT' (this will throw an Error in a future version of PHP) in /var/www/html/test/vendor/codeigniter4/framework/system/CLI/CLI.php:365 Stack trace: #0 /var/www/html/test/vendor/codeigniter4/framework/system/CLI/CLI.php(365): CodeIgniter\Debug\Exceptions->errorHandler(2, 'Use of undefine...', '/var/www/html/t...', 365, Array) #1 /var/www/html/test/vendor/codeigniter4/framework/system/CLI/CLI.php(468): CodeIgniter\CLI\CLI::write() #2 /var/www/html/test/app/Views/errors/cli/error_exception.php(6): CodeIgniter\CLI\CLI::newLine() #3 /var/www/html/test/vendor/codeigniter4/framework/system/Debug/Exceptions.php(278): include('/var/www/html/t...') #4 /var/www/html/test/vendor/codeigniter4/framework/system/Debug/Exceptions.php(147): CodeIgniter\Debug\Exceptions->render(Object(ErrorException), 500) #5 /var/www/html/test/vendor/codeigniter4/framework/system/Debug/Exceptions.php(195): CodeIgniter\Debug\Exceptions->exceptionHandler(Object(ErrorException in /var/www/html/test/vendor/codeigniter4/framework/system/CLI/CLI.php on line 365

I'm using DDEV with Docker to host it, webserver image using NGINX and PHP 7.4. 
I haven't expirenced any problems so far using this image in other projects.
I have alredy tried fresh install, different version of PHP and nothing helped.

  • Taras
    Junior Member

  • Posts: 10
    Threads: 2
    Joined: Aug 2021

    Reputation: 0


Hi,
have you found solution? Same here after updating from the v4.1.1.
When I run "php spark serve" it works fine.

  • Taras
    Junior Member

  • Posts: 10
    Threads: 2
    Joined: Aug 2021

    Reputation: 0


After some investigation I found that there are changes in system/Common.php for is_cli() method that cause current issue.

It's identified as CLI in condition:

PHP Code:

if (stristr(PHP_SAPI'cgi') && getenv('TERM')) 

because PHP_SAPI equals to fpm-fcgi and TERM variable equals to xterm.

Is this correct behavior? How this should be fixed?
(I am using docker with php-fpm and nginx.)


Your getting the errors because STDOUT is not defined, which could be your environment.
You can try adding these constants to see if it will work.

PHP 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')); 

Try that.

What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

  • Taras
    Junior Member

  • Posts: 10
    Threads: 2
    Joined: Aug 2021

    Reputation: 0


As I understand, the problem appears because request from browser incorrectly identified as CLI one. This is why those constants are undefined.

@InsiteFX, I tried to put those definitions. Now I receive blank page (with no errors).

My solution is to put older version of is_cli() into app/Common.php, overriding updated one from system/Common.php.
(I've taken it from //github.com/codeigniter4/CodeIgni...Common.php.)

PHP Code:

function is_cli(): bool
{
    return (PHP_SAPI === 'cli' || defined('STDIN'));

Now pages open fine.


Hi!

Your issue, along with some others, has a fix already in the provisional 4.2 branch.

  • Taras
    Junior Member

  • Posts: 10
    Threads: 2
    Joined: Aug 2021

    Reputation: 0


(08-18-2021, 09:00 PM)paulbalandan Wrote: Hi!

Your issue, along with some others, has a fix already in the provisional 4.2 branch.

Thanks, that code works fine too.

  • fagnerdin
    Member Only

  • Posts: 6
    Threads: 1
    Joined: Oct 2021

    Reputation: 0


[quote pid="389403" dateline="1629345651"]

Quote:Hi!

Your issue, along with some others, has a fix already in the provisional 4.2 branch.

[/quote]

Hi, folks!
Please, where's  4.2 branch?


You can always get the latest version of CodeIgniter from the GitHub Developer Page.

CodeIgniter 4 - Developer Version.

CodeIgniter 4 web framework

What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

  • fagnerdin
    Member Only

  • Posts: 6
    Threads: 1
    Joined: Oct 2021

    Reputation: 0

10-15-2021, 04:26 PM
(This post was last modified: 10-15-2021, 04:48 PM by fagnerdin. Edit Reason: I removed the link from my previous answer. )


By the way, I discovered branch 4.2: "codeigniter4:4.2 - Make CLI detection as independent as possible from interface #4844"

Looks like this isn't accessible branch.

I was facing this issue in a Docker container, I solved it using a ready-made solution from another professional (a Dockerfile).

Thank you for your help.

Postingan terbaru

LIHAT SEMUA