From bc96e0f9e606021eb82cad7e0952caa15835246f Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Wed, 31 May 2023 04:50:53 +0200 Subject: [PATCH] Use real callables for XML handlers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As per PHP docs, the XML functions also accept just a method name as a string, even though it is not actually a callable: Note: Instead of a function name, an array containing an object reference and a method name can also be supplied. PHPStan level 5 will complain though: Parameter #2 $handler of function xml_set_character_data_handler expects callable(): mixed, 'cdata' given. Let’s use proper callables. --- src/Parser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Parser.php b/src/Parser.php index 3929029f5..a58e725ff 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -111,8 +111,8 @@ public function parse(&$data, $encoding, $url = '') xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1); xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, 0); xml_set_object($xml, $this); - xml_set_character_data_handler($xml, 'cdata'); - xml_set_element_handler($xml, 'tag_open', 'tag_close'); + xml_set_character_data_handler($xml, [$this, 'cdata']); + xml_set_element_handler($xml, [$this, 'tag_open'], [$this, 'tag_close']); // Parse! $wrapper = @is_writable(sys_get_temp_dir()) ? 'php://temp' : 'php://memory';