1 | <?php |
||
6 | class xml2Array |
||
|
|||
7 | { |
||
8 | public $stack = []; |
||
9 | public $stack_ref; |
||
10 | public $arrOutput = []; |
||
11 | public $resParser; |
||
12 | public $strXmlData; |
||
13 | |||
14 | public function push_pos(&$pos) |
||
15 | { |
||
16 | $this->stack[count($this->stack)] =& $pos; |
||
17 | $this->stack_ref =& $pos; |
||
18 | } |
||
19 | |||
20 | public function pop_pos() |
||
21 | { |
||
22 | unset($this->stack[count($this->stack) - 1]); |
||
23 | $this->stack_ref =& $this->stack[count($this->stack) - 1]; |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * @param false|string $strInputXML |
||
28 | */ |
||
29 | public function parse($strInputXML) |
||
30 | { |
||
31 | $this->resParser = xml_parser_create('UTF-8'); |
||
32 | xml_set_object($this->resParser, $this); |
||
33 | xml_set_element_handler($this->resParser, 'tagOpen', 'tagClosed'); |
||
34 | |||
35 | xml_set_character_data_handler($this->resParser, 'tagData'); |
||
36 | |||
37 | $this->push_pos($this->arrOutput); |
||
38 | |||
39 | $this->strXmlData = xml_parse($this->resParser, $strInputXML); |
||
40 | if (!$this->strXmlData) { |
||
41 | die(sprintf( |
||
42 | 'XML error: %s at line %d', |
||
43 | xml_error_string(xml_get_error_code($this->resParser)), |
||
44 | xml_get_current_line_number($this->resParser) |
||
45 | )); |
||
46 | } |
||
47 | |||
48 | xml_parser_free($this->resParser); |
||
49 | |||
50 | return $this->arrOutput; |
||
51 | } |
||
52 | |||
53 | public function tagOpen($parser, $name, $attrs) |
||
75 | |||
76 | public function tagData($parser, $tagData) |
||
86 | |||
87 | public function tagClosed($parser, $name) |
||
91 | } |
||
92 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.