@@ -82,7 +82,12 @@ public function encode(mixed $data, string $format, array $context = []): string
82
82
$ encoderIgnoredNodeTypes = $ context [self ::ENCODER_IGNORED_NODE_TYPES ] ?? $ this ->defaultContext [self ::ENCODER_IGNORED_NODE_TYPES ];
83
83
$ ignorePiNode = \in_array (\XML_PI_NODE , $ encoderIgnoredNodeTypes , true );
84
84
if ($ data instanceof \DOMDocument) {
85
- return $ data ->saveXML ($ ignorePiNode ? $ data ->documentElement : null );
85
+ set_error_handler (static function ($ type , $ message ) { throw new NotEncodableValueException ($ message ); }, \E_ERROR | \E_WARNING );
86
+ try {
87
+ return $ data ->saveXML ($ ignorePiNode ? $ data ->documentElement : null );
88
+ } finally {
89
+ restore_error_handler ();
90
+ }
86
91
}
87
92
88
93
$ xmlRootNodeName = $ context [self ::ROOT_NODE_NAME ] ?? $ this ->defaultContext [self ::ROOT_NODE_NAME ];
@@ -97,7 +102,12 @@ public function encode(mixed $data, string $format, array $context = []): string
97
102
$ this ->appendNode ($ dom , $ data , $ format , $ context , $ xmlRootNodeName );
98
103
}
99
104
100
- return $ dom ->saveXML ($ ignorePiNode ? $ dom ->documentElement : null , $ context [self ::SAVE_OPTIONS ] ?? $ this ->defaultContext [self ::SAVE_OPTIONS ]);
105
+ set_error_handler (static function ($ type , $ message ) { throw new NotEncodableValueException ($ message ); }, \E_ERROR | \E_WARNING );
106
+ try {
107
+ return $ dom ->saveXML ($ ignorePiNode ? $ dom ->documentElement : null , $ context [self ::SAVE_OPTIONS ] ?? $ this ->defaultContext [self ::SAVE_OPTIONS ]);
108
+ } finally {
109
+ restore_error_handler ();
110
+ }
101
111
}
102
112
103
113
public function decode (string $ data , string $ format , array $ context = []): mixed
0 commit comments