From 7c9ed7ca27ca07653fc240530b3441d748fea6d4 Mon Sep 17 00:00:00 2001 From: Pekka Laiho Date: Thu, 4 Jun 2020 16:06:56 +0700 Subject: [PATCH] overwrite protection for root env --- src/Env.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Env.php b/src/Env.php index c8b9416..63aff5f 100644 --- a/src/Env.php +++ b/src/Env.php @@ -20,4 +20,14 @@ class Env extends Hash throw new MadLispException("symbol $key not defined in env"); } + + public function set(string $key, $value) + { + // Do not allow overwriting values in root env + if ($this->has($key) && $this->parent == null) { + throw new MadLispException("attempt to overwrite $key in root env"); + } + + return parent::set($key, $value); + } }