Page MenuHomeDevCentral

STDERR isn't defined outside of SAPI CLI context
Open, HighPublic

Description

When Composer isn't install, a message is printed to stderr by former bootstrap code used for phpunit to load libraries.

When this code has been migrated in 026cff14f to use everywhere, that triggers this error:

[20-Oct-2025 18:57:00 UTC] PHP Fatal error:  Uncaught Error: Undefined constant "STDERR" in /var/51-wwwroot/obsidian/workspaces/src/includes/autoload_vendor.php:43
Stack trace:
#0 /var/51-wwwroot/obsidian/workspaces/src/includes/autoload_vendor.php(50): require_vendor_autoload()
#1 /var/51-wwwroot/obsidian/workspaces/src/includes/core.php(25): require_once('/var/51-wwwroot...')
#2 /var/51-wwwroot/obsidian/workspaces/src/index.php(28): include('/var/51-wwwroot...')
#3 {main}
  thrown in /var/51-wwwroot/obsidian/workspaces/src/includes/autoload_vendor.php on line 43

To use the constant STDERR made sense in a43c38521 to write an error message when running phpunit, as it runs in CLI context.

This constant isn't defined in other SAPI, including the php-fpm one, hence the fatal error.

For an hybrid CLI/web context, we can replace fwrite(STDERR, "...") with:

  • error_log("...", 0); -> but need first to check it outputs to stderr in CLI context
  • open a stderr stream, the easiest being to use the wrapper file_put_contents("php://stderr", "...");

Event Timeline

dereckson triaged this task as High priority.Mon, Oct 20, 19:04
dereckson created this task.
dereckson moved this task from Backlog to Dev on the good-first-issue board.