From bf30ba3439e13db17d927094844cf1035f21df95 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Mon, 26 Feb 2018 22:57:43 +0100 Subject: [PATCH] Use reflection to create exception on PHP 7 and use a fallback for PHP 5 --- src/functions.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/functions.php b/src/functions.php index 5cfefa4..0004b20 100644 --- a/src/functions.php +++ b/src/functions.php @@ -57,8 +57,13 @@ function throwable_decode($json) array_pop($properties); + if (PHP_MAJOR_VERSION === 7) { + $throwable = (new ReflectionClass($json['class']))->newInstanceWithoutConstructor(); + } $class = new ReflectionClass($json['class']); - $throwable = new $json['class'](); + if (!isset($throwable)) { + $throwable = new $json['class'](); + } foreach ($properties as $key) { if (!$class->hasProperty($key)) { continue;