diff --git a/lib/webdavlib.php b/lib/webdavlib.php index ea4493aa6fa..bbd3d1b3baa 100644 --- a/lib/webdavlib.php +++ b/lib/webdavlib.php @@ -197,7 +197,10 @@ class webdav_client { function close() { $this->_error_log('closing socket ' . $this->sock); $this->_connection_closed = true; - fclose($this->sock); + if (is_resource($this->sock)) { + // Only close the socket if it is a resource. + fclose($this->sock); + } } /** @@ -640,7 +643,7 @@ class webdav_client { if (strcmp($response['header']['Content-Type'], 'text/xml; charset="utf-8"') == 0) { // ok let's get the content of the xml stuff $this->_parser = xml_parser_create_ns(); - $this->_parserid = (int) $this->_parser; + $this->_parserid = $this->get_parser_id($this->_parser); // forget old data... unset($this->_lock[$this->_parserid]); unset($this->_xmltree[$this->_parserid]); @@ -738,7 +741,7 @@ class webdav_client { if (strcmp($response['header']['Content-Type'], 'text/xml; charset="utf-8"') == 0) { // ok let's get the content of the xml stuff $this->_parser = xml_parser_create_ns(); - $this->_parserid = (int) $this->_parser; + $this->_parserid = $this->get_parser_id($this->_parser); // forget old data... unset($this->_delete[$this->_parserid]); unset($this->_xmltree[$this->_parserid]); @@ -830,7 +833,7 @@ EOD; if (preg_match('#(application|text)/xml;\s?charset=[\'\"]?utf-8[\'\"]?#i', $response['header']['Content-Type'])) { // ok let's get the content of the xml stuff $this->_parser = xml_parser_create_ns('UTF-8'); - $this->_parserid = (int) $this->_parser; + $this->_parserid = $this->get_parser_id($this->_parser); // forget old data... unset($this->_ls[$this->_parserid]); unset($this->_xmltree[$this->_parserid]); @@ -1069,7 +1072,7 @@ EOD; private function _endElement($parser, $name) { // end tag was found... - $parserid = (int) $parser; + $parserid = $this->get_parser_id($parser); $this->_xmltree[$parserid] = substr($this->_xmltree[$parserid],0, strlen($this->_xmltree[$parserid]) - (strlen($name) + 1)); } @@ -1085,7 +1088,7 @@ EOD; */ private function _propfind_startElement($parser, $name, $attrs) { // lower XML Names... maybe break a RFC, don't know ... - $parserid = (int) $parser; + $parserid = $this->get_parser_id($parser); $propname = strtolower($name); if (!empty($this->_xmltree[$parserid])) { @@ -1181,7 +1184,7 @@ EOD; */ private function _delete_startElement($parser, $name, $attrs) { // lower XML Names... maybe break a RFC, don't know ... - $parserid = (int) $parser; + $parserid = $this->get_parser_id($parser); $propname = strtolower($name); $this->_xmltree[$parserid] .= $propname . '_'; @@ -1233,7 +1236,7 @@ EOD; */ private function _lock_startElement($parser, $name, $attrs) { // lower XML Names... maybe break a RFC, don't know ... - $parserid = (int) $parser; + $parserid = $this->get_parser_id($parser); $propname = strtolower($name); $this->_xmltree[$parserid] .= $propname . '_'; @@ -1289,7 +1292,7 @@ EOD; * @access private */ private function _lock_cData($parser, $cdata) { - $parserid = (int) $parser; + $parserid = $this->get_parser_id($parser); if (trim($cdata) <> '') { // $this->_error_log(($this->_xmltree[$parserid]) . '='. htmlentities($cdata)); $this->_lock_ref_cdata .= $cdata; @@ -1747,4 +1750,18 @@ EOD; error_log($err_string); } } + + /** + * Helper method to get the parser id for both PHP 7 and 8. + * + * @param resource|object $parser + * @return int + */ + private function get_parser_id($parser): int { + if (is_object($parser)) { + return spl_object_id($parser); + } else { + return (int) $parser; + } + } }