@@ -46,11 +46,18 @@ public static function createException(
4646
4747 // Replace backtrace instance if we find a valid class insance
4848 foreach ($ backtraceClasses as $ backtraceClass ) {
49+ $ classImplements = \class_implements ($ backtrace ['class ' ]);
50+ $ classParents = \class_parents ($ backtrace ['class ' ]);
51+
52+ if ($ classImplements === false || $ classParents === false ) {
53+ continue ;
54+ }
55+
4956 // Check if the class or interface we are looking for is implemented or used
5057 // by the current backtrace class
5158 if (
52- \in_array ($ backtraceClass , \class_implements ( $ backtrace [ ' class ' ]) , true ) ||
53- \in_array ($ backtraceClass , \class_parents ( $ backtrace [ ' class ' ]) , true ) ||
59+ \in_array ($ backtraceClass , $ classImplements , true ) ||
60+ \in_array ($ backtraceClass , $ classParents , true ) ||
5461 $ backtraceClass === $ backtrace ['class ' ]
5562 ) {
5663 $ lastInstance = $ backtrace ;
@@ -70,13 +77,24 @@ public static function createException(
7077 $ parts = \explode ('\\' , $ assignedBacktraceClass );
7178 $ shownClass = \array_pop ($ parts );
7279
80+ $ classImplements = \class_implements ($ exceptionClass );
81+ $ classParents = \class_parents ($ exceptionClass );
82+
83+ if ($ classImplements === false ) {
84+ $ classImplements = [];
85+ }
86+
87+ if ($ classParents === false ) {
88+ $ classParents = [];
89+ }
90+
7391 // Make sure the provided exception class inherits from Throwable, otherwise replace it with Exception
74- if (!\in_array (\Throwable::class, \class_implements ( $ exceptionClass ) , true )) {
92+ if (!\in_array (\Throwable::class, $ classImplements , true )) {
7593 $ exceptionClass = \Exception::class;
7694 }
7795
7896 // If we have no OriginException child class, we assume the default Exception class constructor is used
79- if (!\in_array (OriginException::class, \class_parents ( $ exceptionClass ) , true ) && $ exceptionClass !== OriginException::class) {
97+ if (!\in_array (OriginException::class, $ classParents , true ) && $ exceptionClass !== OriginException::class) {
8098 /**
8199 * @var \Throwable $exception At this point we know that $exceptionClass inherits from \Throwable for sure
82100 */
0 commit comments