`DOCUMENT_ROOT` from environment in cli is not propagated to $_SERVER['DOCUMENT_ROOT']
未关闭
还没有人认领这个 Issue。
Feature
Status: Needs Triage
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.2k
- 平均合并
- 2 天 15 小时
- 30 天内合并 PR
- 103
描述
Description
The following code:
DOCUMENT_ROOT=/test php -r 'var_dump($_SERVER["DOCUMENT_ROOT"]);'
Resulted in this output:
string(0) ""
But I expected this output instead:
string(5) "/test"
with a file the out is the same
I think the culprit is https://github.com/php/php-src/blob/42f994cd05da353c93cd65775026859f664289a3/sapi/cli/php_cli.c#L344 as the only mention of DOCUMENT_ROOT for php-cli
PHP Version
PHP 8.4.15 (cli) (built: Nov 20 2025 19:00:52) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.4.15, Copyright (c) Zend Technologies
with Zend OPcache v8.4.15, Copyright (c), by Zend Technologies
Operating System
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 sapi/cli/php_cli.c 中 issue 所确定的 DOCUMENT_ROOT 处理开始,分别在有文件和无文件的情况下复现命令行示例。跟踪环境值如何到达 $_SERVER;完成的标准是 PHP CLI 在两种情况下都将 /test 暴露为 $_SERVER['DOCUMENT_ROOT']。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, php
- 领域
- cli
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 48/100