@@ -109,10 +109,17 @@ public function getWriter(): Writer
109109 */
110110 public function parse ($ input , ?string $ contextUri = null , ?string &$ rootElementName = null )
111111 {
112- if (is_resource ($ input )) {
112+ if (! is_string ($ input )) {
113113 // Unfortunately the XMLReader doesn't support streams. When it
114114 // does, we can optimize this.
115- $ input = (string ) stream_get_contents ($ input );
115+ if (is_resource ($ input )) {
116+ $ input = (string ) stream_get_contents ($ input );
117+ } else {
118+ // Input is not a string and not a resource.
119+ // Therefore, it has to be a closed resource.
120+ // Effectively empty input has been passed in.
121+ $ input = '' ;
122+ }
116123 }
117124
118125 // If input is empty, then it's safe to throw an exception
@@ -153,10 +160,17 @@ public function parse($input, ?string $contextUri = null, ?string &$rootElementN
153160 */
154161 public function expect ($ rootElementName , $ input , ?string $ contextUri = null )
155162 {
156- if (is_resource ($ input )) {
163+ if (! is_string ($ input )) {
157164 // Unfortunately the XMLReader doesn't support streams. When it
158165 // does, we can optimize this.
159- $ input = (string ) stream_get_contents ($ input );
166+ if (is_resource ($ input )) {
167+ $ input = (string ) stream_get_contents ($ input );
168+ } else {
169+ // Input is not a string and not a resource.
170+ // Therefore, it has to be a closed resource.
171+ // Effectively empty input has been passed in.
172+ $ input = '' ;
173+ }
160174 }
161175
162176 // If input is empty, then it's safe to throw an exception
0 commit comments