@@ -42,27 +42,28 @@ class ExceptionCaster
42
42
43
43
public static function castException (\Exception $ e , array $ a , Stub $ stub , $ isNested , $ filter = 0 )
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
if (!($ filter & Caster::EXCLUDE_VERBOSE )) {
49
50
static ::filterTrace ($ trace , static ::$ traceArgs );
50
51
51
52
if (null !== $ trace ) {
52
- $ a ["\0 Exception \0 trace " ] = $ trace ;
53
+ $ a [$ xPrefix . ' trace ' ] = $ trace ;
53
54
}
54
55
}
55
- if (empty ($ a ["\0 Exception \0 previous " ])) {
56
- unset($ a ["\0 Exception \0 previous " ]);
56
+ if (empty ($ a [$ xPrefix . ' previous ' ])) {
57
+ unset($ a [$ xPrefix . ' previous ' ]);
57
58
}
58
- unset($ a ["\0 Exception \0 string " ], $ a ["\0 + \0 xdebug_message " ], $ a ["\0 + \0 __destructorException " ]);
59
+ unset($ a [$ xPrefix . ' string ' ], $ a [Caster:: PREFIX_DYNAMIC . ' xdebug_message ' ], $ a [Caster:: PREFIX_DYNAMIC . ' __destructorException ' ]);
59
60
60
61
return $ a ;
61
62
}
62
63
63
64
public static function castErrorException (\ErrorException $ e , array $ a , Stub $ stub , $ isNested )
64
65
{
65
- if (isset ($ a [$ s = "\0 * \0 severity " ], self ::$ errorTypes [$ a [$ s ]])) {
66
+ if (isset ($ a [$ s = Caster:: PREFIX_PROTECTED . ' severity ' ], self ::$ errorTypes [$ a [$ s ]])) {
66
67
$ a [$ s ] = new ConstStub (self ::$ errorTypes [$ a [$ s ]], $ a [$ s ]);
67
68
}
68
69
@@ -71,23 +72,21 @@ public static function castErrorException(\ErrorException $e, array $a, Stub $st
71
72
72
73
public static function castThrowingCasterException (ThrowingCasterException $ e , array $ a , Stub $ stub , $ isNested )
73
74
{
74
- $ b = (array ) $ a ["\0Exception \0previous " ];
75
-
76
- if (isset ($ b ["\0* \0message " ])) {
77
- $ a ["\0~ \0message " ] = $ b ["\0* \0message " ];
78
- }
79
-
80
- if (isset ($ a ["\0Exception \0trace " ])) {
81
- $ b ["\0Exception \0trace " ][0 ] += array (
82
- 'file ' => $ b ["\0* \0file " ],
83
- 'line ' => $ b ["\0* \0line " ],
75
+ $ prefix = Caster::PREFIX_PROTECTED ;
76
+ $ xPrefix = PHP_VERSION_ID >= 70000 ? "\0BaseException \0" : "\0Exception \0" ;
77
+ $ b = (array ) $ a [$ xPrefix .'previous ' ];
78
+
79
+ if (isset ($ a [$ xPrefix .'trace ' ][0 ])) {
80
+ $ b [$ xPrefix .'trace ' ][0 ] += array (
81
+ 'file ' => $ b [$ prefix .'file ' ],
82
+ 'line ' => $ b [$ prefix .'line ' ],
84
83
);
85
- array_splice ($ b ["\0 Exception \0 trace " ], -1 - count ($ a ["\0 Exception \0 trace " ]));
86
- static ::filterTrace ($ b ["\0 Exception \0 trace " ], false );
87
- $ a ["\0 ~ \0 trace " ] = $ b ["\0 Exception \0 trace " ];
84
+ array_splice ($ b [$ xPrefix . ' trace ' ], -1 - count ($ a [$ xPrefix . ' trace ' ]));
85
+ static ::filterTrace ($ b [$ xPrefix . ' trace ' ], false );
86
+ $ a [Caster:: PREFIX_VIRTUAL . ' trace ' ] = $ b [$ xPrefix . ' trace ' ];
88
87
}
89
88
90
- unset($ a ["\0 Exception \0 trace " ], $ a ["\0 Exception \0 previous " ], $ a ["\0 * \0 code " ], $ a ["\0 * \0 file " ], $ a ["\0 * \0 line " ]);
89
+ unset($ a [$ xPrefix . ' trace ' ], $ a [$ xPrefix . ' previous ' ], $ a [$ prefix . ' code ' ], $ a [$ prefix . ' file ' ], $ a [$ prefix . ' line ' ]);
91
90
92
91
return $ a ;
93
92
}
0 commit comments