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

オープン
#21,305 コメント 1 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 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
  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
主要言語
PHP
スター
3.6k
フォーク
800
平均マージ
15時間 20分
マージ済み PR(30日)
715

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

craftcms/cms のほかの issue

craftcms/cms の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。