[6.x]: Duplicate key in .env crashes the app when config is cached ("Constant … already defined")
Maintainer thường phản hồi trong vòng 1 ngày
@riasvdv đang làm issue này rồi.
Từ ngày 2/12/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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
- Ngôn ngữ chính
- PHP
- Star
- 3.6k
- Fork
- 800
- Merge trung bình
- 15 giờ 20 phút
- Pull request đã merge (30 ngày)
- 715
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của craftcms/cms
-
bug repo:cms
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
craftcms/cms#21301 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug repo:cms
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 58/100
craftcms/cms#21307 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug repo:cms
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
craftcms/cms#21306 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug repo:cms
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
craftcms/cms#21303 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug repo:cms
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 66/100
craftcms/cms#21298 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Document lexicon.default.userconfig and lexicon.default.userconfig.enforced in config.sample.phpĐang mởenhancement feature: settings good first issue
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
nextcloud/integration_openai#480 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
a11y
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
omeka/plugin-Contribution#84 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
recca0120/vscode-phpunit#620 ·
Maintainer thường phản hồi trong vòng 1 ngày