php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6500 XML - startElementHandler
Submitted: 2000-09-02 05:05 UTC Modified: 2002-01-27 05:20 UTC
Votes:3
Avg. Score:2.3 ± 0.9
Reproduced:0 of 1 (0.0%)
From: mario dot staas at free-e-project dot org Assigned:
Status: No Feedback Package: XML related
PHP Version: 4.0.2 OS: SuSE Linux 6.4
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
20 + 42 = ?
Subscribe to this entry?

 
 [2000-09-02 05:05 UTC] mario dot staas at free-e-project dot org
I use a class to handle XML-files. After the installation of version 4.0.2 (up to CVS-version 200009020045) I have problems with the XML functions.

In the "startElementHandler" function I move the attribs into a variable ($this->DATA). A var_dump inside the "startElementHandler" shows the correct image of the XML attribs. But after parsing a XML-file (outside xml_set_element_handler or xml_set_character_data_handler) a var_dump($this->DATA) shows the following resault: 

array(0) 

In PHP beta, PHP4.0.0 and PHP4.0.1 I had no problems.

I use a default php.ini file (without ZendOptimizer).

Modules: default + mysql, zlib


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-09-02 22:43 UTC] sniper@php.net
Please try latest CVS or snapshot from http://snaps.php.net  as this should be
fixed 2 days ago.  Reopen this bug report if problem still exists.

--Jani
 [2000-09-03 05:58 UTC] mario dot staas at free-e-project dot org
Sorry! But the error still exists!

I know the (first) bug in PHP4.0.2 (warnings -> function of startElementHandler not found ....) and it?s fixed.
The bug I described is a little different. It is not the "startElementHandler" itself.

1.  CONSTRUCTOR

        function XML_HANDLER() {  
            $this->O_XML_PARSER = xml_parser_create();
            xml_set_object($this->O_XML_PARSER,&$this);
            xml_set_element_handler($this->O_XML_PARSER,"Tag_Start","Tag_End");
            xml_set_character_data_handler($this->O_XML_PARSER,"CData");
        }

2. Parse from file (function)
           
            ... some statements
            while($L_LINE = fread($L_FP, 4096)) {
                $this->O_LINE++;
                if(!xml_parse($this->O_XML_PARSER, $L_LINE, feof($L_FP))) 
                        die(sprintf("XML error: %s at line %d in file %s",
                            xml_error_string(xml_get_error_code($this->O_XML_PARSER)),
                            xml_get_current_line_number($this->O_XML_PARSER), $A_FILE));          
            }
            fclose($L_FP);

---->     var_dump($this->O_DATA);      
------------OUTPUT------------> array(0) ----> ERROR!!!!!!!!!!! 

3. Tag_Start function 

            function Tag_Start($A_PARSER, $A_ELE_NAME, $A_ATTRIBS) {
                if (!isset($A_ATTRIBS)) return;
                while(list($L_KEY, $L_VALUE) = each($A_ATTRIBS)) {
                    $L_EVAL = $this->O_EVAL .'["ATTRIBUTE"]' .'["' .strtoupper($L_KEY) .'"]';
                    eval("\$this->O_DATA$L_EVAL = $L_VALUE;");
                }

---->        var_dump($this->O_DATA);   
-----------OUTPUT----------->  array(1) { ["FEP_VARS"]=> array(1) { ["STAT"]=> array(1) { ["TORPEDO"]=> array(1) { ["ATTRIBUTE"]=> array(2) { ["VERSION"]=> string(5) "V0300" ["DATE"]=> int(20000701) } } } } }   ----> OK !!!!!!!!!!!

            }

This is a very critical bug! Please check it...
 [2000-09-03 06:07 UTC] stas@php.net
1. Don't use &$this syntax. It is decprecated
2. Could you cut down your script as much as possible and post it and the minimal XML reproducing buggy behaviour?
 [2000-09-03 07:27 UTC] mario dot staas at free-e-project dot org
1. What do you mean with "It is decprecated"? 
   I used the SYNTAX of the DOCUMENTATION 
   --> PHP -> XML -> xml_set_object
   "<?php
    class xml  {
    var $parser;

    function xml() { 
        $this->parser = xml_parser_create();
        xml_set_object($this->parser,&$this);"
                                     ------
    
   How is the correct syntax?

2. XML-Class

   I removed 100 lines of code. Some parts now looking strange. The XML-HANDLER is just a small (but important) part of our ContentSystem.

<?PHP
    class XML_HANDLER {
        var $O_DATA = array();                 // The XML-PARSER resault
        var $O_STRICT = true;                  // If 'true' overwrite cdata is not allowed
        var $O_STACK = array();                // TAG-stack: tag_A --> tag_B --> tag_n
        var $O_XML_PARSER;                     // XML OBJECT PARSER

        function XML_HANDLER() {
            $this->O_LEVEL = -1;
            $this->O_XML_PARSER = xml_parser_create();
            xml_set_object($this->O_XML_PARSER,&$this);
            xml_set_element_handler($this->O_XML_PARSER,"Tag_Start","Tag_End");
            xml_set_character_data_handler($this->O_XML_PARSER,"CData");
            xml_parser_set_option($this->O_XML_PARSER, XML_OPTION_CASE_FOLDING, 0);
        }

        function Run($A_FILE, $A_FILE_TYPE) {
            $this->O_FILE_TYPE = $A_FILE_TYPE;
            return $this->ParseFromFile($A_FILE);
        }

        function ParseFromFile($A_FILE) {
            $this->O_FILE = $A_FILE;
            $L_FP = @fopen($A_FILE, "r");
            while($L_LINE = fread($L_FP, 4096))
                xml_parse($this->O_XML_PARSER, $L_LINE, feof($L_FP));
            fclose($L_FP);
// var_dump($this->O_DATA);
// ERROR !!!! $this->O_DATA is empty !!!!!!!!
            return $this->O_DATA[$this->O_FILE_TYPE];
        }

        function Tag_Start($A_PARSER, $A_ELE_NAME, $A_ATTRIBS) {
            $this->O_LEVEL++;
            $this->O_STACK[$this->O_LEVEL] = $A_ELE_NAME;
            $L_EVAL = $this->Bild_Eval();
            if (!$this->IsStrict()) {
                eval("\$L_ISSET = isset(\$this->O_DATA$L_EVAL);");
                if ($L_ISSET) {
                    $L_EVAL = $this->O_EVAL .'[0]';
                    eval("\$L_VAL = isset(\$this->O_DATA$L_EVAL);");
                    if (!$L_VAL) {
                         $L_EVAL = $L_EVAL2 = $this->O_EVAL;
                         $L_EVAL2 .= '[0]';
                         eval("\$L_DATA = \$this->O_DATA$L_EVAL;");
                         eval("unset(\$this->O_DATA$L_EVAL);");
                         eval("\$this->O_DATA$L_EVAL2 = \$L_DATA;");
                    }
                    $L_EVAL = $this->O_EVAL;
                    eval("\$L_COUNT = count(\$this->O_DATA$L_EVAL);");
                    $this->O_APPEND[$this->O_LEVEL] = "[$L_COUNT]";
                    $this->Bild_Eval();
                }
            }
            if (!isset($A_ATTRIBS)) return;
            while(list($L_KEY, $L_VALUE) = each($A_ATTRIBS)) {
                $L_EVAL = $this->O_EVAL .'["ATTRIBUTE"]' .'["' .strtoupper($L_KEY) .'"]';
                eval("\$this->O_DATA$L_EVAL = $L_VALUE;");
            }
// var_dump($this->O_DATA) 
// OK, no error !!!!!!
        }

        function Bild_Eval() {
            for ($L_L2=0; $L_L2 < $this->O_LEVEL+1; $L_L2++)
                $L_EVAL = $L_EVAL .'["' .$this->O_STACK[$L_L2] .'"]' .$this->O_APPEND[$L_L2];
            return $this->O_EVAL = $L_EVAL;
        }

        function Tag_End($A_PARSER, $A_ELE_NAME) {
            unset($this->O_STACK[$this->O_LEVEL]);
            unset($this->O_APPEND[$this->O_LEVEL]);
            $this->O_LEVEL--;
        }

        function CData($A_PARSER, $A_DATA) {
            if (strlen(trim($A_DATA))==0) return;
            $L_EVAL = $this->O_EVAL .'["VALUE"]';
            eval("\$this->O_DATA$L_EVAL = $A_DATA;");
        }
        function IsStrict() { return $this->O_STRICT; }
        function SetStrict() { $this->O_STRICT = true; }
        function SetUnStrict() { $this->O_STRICT = false; }
    }
?>


3. XML-File
  <?xml version="1.0"?>
  <FEP_VARS>
  <STAT>
    <TORPEDO VERSION="V0300" DATE="20000701"/>
  </STAT>
  <RUNTIME>
    <SESSION>
      <NAME>"SESSID"</NAME>
      <TYPE>"s"</TYPE>
    </SESSION>
    <GENERATION>"3"</GENERATION>
    <DHTML>true</DHTML>
    <LANGUAGE>"en"</LANGUAGE>
    <CODE>"US"</CODE>
    <ERROR_LOG>"true"</ERROR_LOG>
    <IP_LOG>"true"</IP_LOG>
    <OBJECT>"USER"</OBJECT>
    <DB_HOE>true</DB_HOE>
    <DB>"fep_db"</DB>
    <DDT>"main"</DDT>
  </RUNTIME>
  </FEP_VARS>
 [2002-01-06 09:03 UTC] mfischer@php.net
Does this still apply to 4.1.1 ?
 [2002-01-27 05:20 UTC] sander@php.net
No feedback.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 12:01:27 2024 UTC