Skip to content

Commit

Permalink
Use real callables for XML handlers
Browse files Browse the repository at this point in the history
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 simplepie#2 $handler of function xml_set_character_data_handler expects callable(): mixed, 'cdata' given.

Let’s use proper callables.
  • Loading branch information
jtojnar committed Aug 6, 2023
1 parent a2807dc commit bc96e0f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit bc96e0f

Please sign in to comment.