3v4l.org

run code in 300+ PHP versions simultaneously
<?php class testParser { /** @var resource */ private $parser; /** * @param string $encoding */ public function __construct($encoding = 'UTF-8') { echo __CLASS__ . ' ' . __METHOD__ . ' ' . __LINE__ . "<br>"; $parser = new ParserObject($encoding); $this->parser = $parser->getParser(); xml_set_character_data_handler($this->parser, [$this, 'data']); echo __CLASS__ . ' ' . __METHOD__ . ' ' . __LINE__ . "<br>"; } public function parseAction($data) { echo __CLASS__ . ' ' . __METHOD__ . ' ' . __LINE__ . "<br>"; return xml_parse($this->parser, $data); } public function data($parser, $cdata) { echo __CLASS__ . ' ' . __METHOD__ . ' ' . __LINE__ . "<br>"; } } class ParserObject { /** @var resource */ private $xml_parser_resource; public function __construct($encoding) { echo __CLASS__ . ' ' . __METHOD__ . ' ' . __LINE__ . "<br>"; $this->xml_parser_resource = xml_parser_create($encoding); } public function getParser() { echo __CLASS__ . ' ' . __METHOD__ . ' ' . __LINE__ . "<br>"; return $this->xml_parser_resource; } public function __destruct() { echo __CLASS__ . ' ' . __METHOD__ . ' ' . __LINE__ . "<br>"; xml_parser_free($this->xml_parser_resource); } } $content = '<?xml version="1.0" ?><note><body>Do</body></note>'; echo __LINE__ . "<br>"; $parser = new testParser(); echo __LINE__ . "<br>"; $parser->parseAction($content); echo __LINE__ . "<br>";

preferences:
41.15 ms | 402 KiB | 5 Q