[6.x]: Duplicate key in .env crashes the app when config is cached ("Constant … already defined")

Đang mở
#21,305 1 bình luận 0 reaction 1 người được giao Xem trên GitHub

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
  1. Add a duplicate key to .env:
    REPRO_DUPLICATE=one
    REPRO_DUPLICATE=two
    
  2. Run php artisan config:cache.
  3. 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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của craftcms/cms

Tất cả issue của craftcms/cms

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.