From 128e377712f6e133074b1ed248aed4bc56d81711 Mon Sep 17 00:00:00 2001 From: Sebastian Meyer Date: Fri, 29 Sep 2023 19:28:08 +0200 Subject: [PATCH] Catch exceptions --- src/Traits/Getter.php | 7 ++++++- src/Traits/Setter.php | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Traits/Getter.php b/src/Traits/Getter.php index cd2ce95..41f65a6 100644 --- a/src/Traits/Getter.php +++ b/src/Traits/Getter.php @@ -65,6 +65,11 @@ trait Getter */ final public function __isset(string $property): bool { - return !empty($this->__get($property)); + try { + $value = $this->__get($property); + } catch (\InvalidArgumentException) { + $value = null; + } + return !empty($value); } } diff --git a/src/Traits/Setter.php b/src/Traits/Setter.php index 568a639..6aa3e85 100644 --- a/src/Traits/Setter.php +++ b/src/Traits/Setter.php @@ -68,6 +68,8 @@ trait Setter */ final public function __unset(string $property): void { - $this->__set($property, null); + try { + $this->__set($property, null); + } catch (\InvalidArgumentException) {} } }