[6.x]: Duplicate key in .env crashes the app when config is cached ("Constant … already defined")
维护者通常 1 天内回复
@riasvdv 已经在做这个了。
开始于 2026年12月2日。
评估
这个 Issue 还没有评估数据。
描述
What happened?
Description
With a cached config (config:cache or optimize), Craft reloads .env through ConstAdapter, whose write() calls define() without checking defined(). A key that appears twice in .env then throws "Constant X already defined" and the app won't boot. Without a cached config, and in plain Laravel, duplicate keys are fine.
We hit this on a Laravel Cloud deploy, where optimize runs during the build:
Constant SESSION_DRIVER already defined, this will be an error in PHP 9
at vendor/craftcms/cms/src/Config/ConstAdapter.php:54
Steps to reproduce
- Add a duplicate key to
.env:REPRO_DUPLICATE=one REPRO_DUPLICATE=two - Run
php artisan config:cache. - Run any Artisan command, such as
php artisan about.
Expected behavior
The app boots and the last value wins, the same as without a cached config and the same as plain Laravel.
Actual behavior
Every Artisan command and request fails with Constant REPRO_DUPLICATE already defined, this will be an error in PHP 9 from ConstAdapter.php:54.
A possible fix is for ConstAdapter::write() to skip (or return false for) names that are already defined().
Craft CMS version
6.0.0-beta.3
PHP version
8.5.13
Operating system and version
macOS (Laravel Herd) locally; Laravel Cloud (production)
Database type and version
MySQL
Image driver and version
Imagick 3.8.1 (ImageMagick 7.1.2-34) on Laravel Cloud
Installed plugins and versions
- craftcms/ckeditor 6.0.0-beta.2
- 主要语言
- PHP
- 星标
- 3.6k
- 派生
- 800
- 平均合并
- 15 小时 20 分钟
- 30 天内合并 PR
- 715
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
craftcms/cms 的其他 Issue
-
bug repo:cms
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
bug repo:cms
难度 3/5 1-2 天 新手友好度 58/100
维护者通常 1 天内回复
-
bug repo:cms
难度 3/5 1-2 天 新手友好度 55/100
维护者通常 1 天内回复
-
bug repo:cms
难度 3/5 1-2 天 新手友好度 52/100
维护者通常 1 天内回复
-
bug repo:cms
难度 3/5 1-2 天 新手友好度 66/100
维护者通常 1 天内回复
相似的 Issue
-
Document lexicon.default.userconfig and lexicon.default.userconfig.enforced in config.sample.php未关闭enhancement feature: settings good first issue
难度 1/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
nextcloud/integration_openai#480 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
a11y
难度 2/5 1-3 小时 新手友好度 68/100
omeka/plugin-Contribution#84 ·
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
recca0120/vscode-phpunit#620 ·
维护者通常 1 天内回复