1--TEST-- 2Test xml_set_element_handler handlers as trampoline callback 3--EXTENSIONS-- 4xml 5--FILE-- 6<?php 7 8class CustomXmlParser 9{ 10 public function startHandler($XmlParser, $tag, $attr) 11 { 12 echo 'Method start handler: ', $tag, PHP_EOL; 13 } 14 15 public function endHandler($XmlParser, $tag) 16 { 17 echo 'Method end handler: ', $tag, PHP_EOL; 18 } 19} 20 21$customParser = new CustomXmlParser; 22 23class TrampolineTest { 24 public function __call(string $name, array $arguments) { 25 echo 'Trampoline for ', $name, PHP_EOL; 26 echo 'Tag: ', $arguments[1], PHP_EOL; 27 } 28} 29 30$o = new TrampolineTest(); 31$startCallback = [$o, 'start_handler']; 32$endCallback = [$o, 'end_handler']; 33 34$xml = <<<HERE 35<a> 36 <b/> 37 <c>Text</c> 38</a> 39HERE; 40 41echo "Both handlers are trampolines:\n"; 42$parser = xml_parser_create(); 43xml_set_element_handler($parser, $startCallback, $endCallback); 44xml_parse($parser, $xml, true); 45xml_parser_free($parser); 46 47echo "\nStart handler is trampoline, end handler method string:\n"; 48$parser = xml_parser_create(); 49xml_set_object($parser, $customParser); 50xml_set_element_handler($parser, $startCallback, 'endHandler'); 51xml_parse($parser, $xml, true); 52xml_parser_free($parser); 53 54echo "\nEnd handler is trampoline, start handler method string:\n"; 55$parser = xml_parser_create(); 56xml_set_object($parser, $customParser); 57xml_set_element_handler($parser, 'startHandler', $endCallback); 58xml_parse($parser, $xml, true); 59xml_parser_free($parser); 60 61?> 62--EXPECTF-- 63Both handlers are trampolines: 64Trampoline for start_handler 65Tag: A 66Trampoline for start_handler 67Tag: B 68Trampoline for end_handler 69Tag: B 70Trampoline for start_handler 71Tag: C 72Trampoline for end_handler 73Tag: C 74Trampoline for end_handler 75Tag: A 76 77Start handler is trampoline, end handler method string: 78 79Deprecated: Function xml_set_object() is deprecated since 8.4, provide a proper method callable to xml_set_*_handler() functions in %s on line %d 80 81Deprecated: xml_set_element_handler(): Passing non-callable strings is deprecated since 8.4 in %s on line %d 82Trampoline for start_handler 83Tag: A 84Trampoline for start_handler 85Tag: B 86Method end handler: B 87Trampoline for start_handler 88Tag: C 89Method end handler: C 90Method end handler: A 91 92End handler is trampoline, start handler method string: 93 94Deprecated: Function xml_set_object() is deprecated since 8.4, provide a proper method callable to xml_set_*_handler() functions in %s on line %d 95 96Deprecated: xml_set_element_handler(): Passing non-callable strings is deprecated since 8.4 in %s on line %d 97Method start handler: A 98Method start handler: B 99Trampoline for end_handler 100Tag: B 101Method start handler: C 102Trampoline for end_handler 103Tag: C 104Trampoline for end_handler 105Tag: A 106