@@ -42,18 +42,19 @@ class ExceptionCaster
42
42
43
43
public static function castException (\Exception $ e , array $ a , Stub $ stub , $ isNested )
44
44
{
45
- $ trace = $ a ["\0Exception \0trace " ];
46
- unset($ a ["\0Exception \0trace " ]); // Ensures the trace is always last
45
+ $ xPrefix = PHP_VERSION_ID >= 70000 ? "\0BaseException \0" : "\0Exception \0" ;
46
+ $ trace = $ a [$ xPrefix .'trace ' ];
47
+ unset($ a [$ xPrefix .'trace ' ]); // Ensures the trace is always last
47
48
48
49
static ::filterTrace ($ trace , static ::$ traceArgs );
49
50
50
51
if (null !== $ trace ) {
51
- $ a ["\0 Exception \0 trace " ] = $ trace ;
52
+ $ a [$ xPrefix . ' trace ' ] = $ trace ;
52
53
}
53
- if (empty ($ a ["\0 Exception \0 previous " ])) {
54
- unset($ a ["\0 Exception \0 previous " ]);
54
+ if (empty ($ a [$ xPrefix . ' previous ' ])) {
55
+ unset($ a [$ xPrefix . ' previous ' ]);
55
56
}
56
- unset($ a ["\0 Exception \0 string " ], $ a ["\0+ \0xdebug_message " ], $ a ["\0+ \0__destructorException " ]);
57
+ unset($ a [$ xPrefix . ' string ' ], $ a ["\0+ \0xdebug_message " ], $ a ["\0+ \0__destructorException " ]);
57
58
58
59
return $ a ;
59
60
}
@@ -69,23 +70,20 @@ public static function castErrorException(\ErrorException $e, array $a, Stub $st
69
70
70
71
public static function castThrowingCasterException (ThrowingCasterException $ e , array $ a , Stub $ stub , $ isNested )
71
72
{
72
- $ b = (array ) $ a ["\0Exception \0previous " ];
73
+ $ xPrefix = PHP_VERSION_ID >= 70000 ? "\0BaseException \0" : "\0Exception \0" ;
74
+ $ b = (array ) $ a [$ xPrefix .'previous ' ];
73
75
74
- if (isset ($ b ["\0* \0message " ])) {
75
- $ a ["\0~ \0message " ] = $ b ["\0* \0message " ];
76
- }
77
-
78
- if (isset ($ a ["\0Exception \0trace " ])) {
79
- $ b ["\0Exception \0trace " ][0 ] += array (
76
+ if (isset ($ a [$ xPrefix .'trace ' ][0 ])) {
77
+ $ b [$ xPrefix .'trace ' ][0 ] += array (
80
78
'file ' => $ b ["\0* \0file " ],
81
79
'line ' => $ b ["\0* \0line " ],
82
80
);
83
- array_splice ($ b ["\0 Exception \0 trace " ], -1 - count ($ a ["\0 Exception \0 trace " ]));
84
- static ::filterTrace ($ b ["\0 Exception \0 trace " ], false );
85
- $ a ["\0~ \0trace " ] = $ b ["\0 Exception \0 trace " ];
81
+ array_splice ($ b [$ xPrefix . ' trace ' ], -1 - count ($ a [$ xPrefix . ' trace ' ]));
82
+ static ::filterTrace ($ b [$ xPrefix . ' trace ' ], false );
83
+ $ a ["\0~ \0trace " ] = $ b [$ xPrefix . ' trace ' ];
86
84
}
87
85
88
- unset($ a ["\0 Exception \0 trace " ], $ a ["\0 Exception \0 previous " ], $ a ["\0* \0code " ], $ a ["\0* \0file " ], $ a ["\0* \0line " ]);
86
+ unset($ a [$ xPrefix . ' trace ' ], $ a [$ xPrefix . ' previous ' ], $ a ["\0* \0code " ], $ a ["\0* \0file " ], $ a ["\0* \0line " ]);
89
87
90
88
return $ a ;
91
89
}
0 commit comments