3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php error_reporting(E_ALL); class XML { var $parser; #a reference to the XML parser var $document; #the entire XML structure built up so far var $current; #a pointer to the current item - what is this var $parent; #a pointer to the current parent - the parent will be an array var $parents; #an array of the most recent parent at each level var $last_opened_tag; function XML($data=null){ $this->parser = xml_parser_create(); xml_parser_set_option ($this->parser, XML_OPTION_CASE_FOLDING, 0); xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, "open", "close"); xml_set_character_data_handler($this->parser, "data"); # register_shutdown_function(array(&$this, 'destruct')); } function destruct(){ xml_parser_free($this->parser); } function parse($data){ $this->document = array(); $this->parent = &$this->document; $this->parents = array(); $this->last_opened_tag = NULL; xml_parse($this->parser, $data); return $this->document; } function open($parser, $tag, $attributes){ #echo "Opening tag $tag<br>\n"; $this->data = ""; $this->last_opened_tag = $tag; #tag is a string if(array_key_exists($tag, $this->parent)){ #echo "There's already an instance of '$tag' at the current level ($level)<br>\n"; if(is_array($this->parent[$tag]) and array_key_exists(0, $this->parent[$tag])){ #if the keys are numeric #need to make sure they're numeric (account for attributes) $key = count_numeric_items($this->parent[$tag]); #echo "There are $key instances: the keys are numeric.<br>\n"; }else{ #echo "There is only one instance. Shifting everything around<br>\n"; $temp = &$this->parent[$tag]; unset($this->parent[$tag]); $this->parent[$tag][0] = &$temp; if(array_key_exists("$tag attr", $this->parent)){ #shift the attributes around too if they exist $temp = &$this->parent["$tag attr"]; unset($this->parent["$tag attr"]); $this->parent[$tag]["0 attr"] = &$temp; } $key = 1; } $this->parent = &$this->parent[$tag]; }else{ $key = $tag; } if($attributes){ $this->parent["$key attr"] = $attributes; } $this->parent[$key] = array(); $this->parent = &$this->parent[$key]; array_unshift($this->parents, &$this->parent); } function data($parser, $data){ #echo "Data is '", htmlspecialchars($data), "'<br>\n"; if($this->last_opened_tag != NULL){ $this->data .= $data; } } function close($parser, $tag){ #echo "Close tag $tag<br>\n"; if($this->last_opened_tag == $tag){ $this->parent = $this->data; $this->last_opened_tag = NULL; } array_shift($this->parents); $this->parent = &$this->parents[0]; } }
based on h7cpA
Output for 5.4.0 - 5.4.32
Fatal error: Call-time pass-by-reference has been removed in /in/Ductq on line 69
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Deprecated: Call-time pass-by-reference has been deprecated in /in/Ductq on line 69
Output for 5.2.7 - 5.2.17
Warning: Call-time pass-by-reference has been deprecated in /in/Ductq on line 69
Output for 5.2.5 - 5.2.6
Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of array_unshift(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file in /in/Ductq on line 69
Output for 5.2.1 - 5.2.4
Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of array_unshift(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. in /in/Ductq on line 69
Output for 4.3.0 - 4.4.9, 5.1.3 - 5.2.0
Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of array_unshift(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in /in/Ductq on line 69
Output for 5.0.0 - 5.1.2
Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/Ductq on line 4 Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/Ductq on line 5 Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/Ductq on line 6 Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/Ductq on line 7 Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/Ductq on line 8 Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/Ductq on line 10 Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of array_unshift(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in /in/Ductq on line 69