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

Aperta
#21,305 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@riasvdv ci sta già lavorando.

Dal 2/12/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

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
Lingua principale
PHP
Stelle
3.6k
Fork
800
Merge medio
15h 20m
PR unite (30g)
715

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di craftcms/cms

Tutte le issue di craftcms/cms

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.