3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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>";
based on UWXMd
Output for 7.0.20 - 7.2.0
58<br>testParser testParser::__construct 13<br>ParserObject ParserObject::__construct 39<br>ParserObject ParserObject::getParser 45<br>testParser testParser::__construct 17<br>ParserObject ParserObject::__destruct 51<br>60<br>testParser testParser::parseAction 22<br>testParser testParser::data 28<br>62<br>
Output for 7.0.0 - 7.0.6
58<br>testParser testParser::__construct 13<br>ParserObject ParserObject::__construct 39<br>ParserObject ParserObject::getParser 45<br>testParser testParser::__construct 17<br>ParserObject ParserObject::__destruct 51<br>60<br>testParser testParser::parseAction 22<br> Warning: xml_parse(): supplied resource is not a valid XML Parser resource in /in/jCBM4 on line 23 62<br>
Output for 5.4.2 - 5.6.28
58<br>testParser testParser::__construct 13<br>ParserObject ParserObject::__construct 39<br>ParserObject ParserObject::getParser 45<br>testParser testParser::__construct 17<br>ParserObject ParserObject::__destruct 51<br>60<br>testParser testParser::parseAction 22<br> Warning: xml_parse(): 4 is not a valid XML Parser resource in /in/jCBM4 on line 23 62<br>
Output for 5.3.18 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/jCBM4 on line 16
Process exited with code 255.