From:             [EMAIL PROTECTED]
Operating system: Win98SE/Linux
PHP version:      4.0.6
PHP Bug Type:     XML related
Bug description:  XML methods don't have $this set!

When you use XML methods in a script, $this doesn't get set or is buggy.
That means you can't use instance variables or methods of that object.

When you run the following script you only get SE,SE,EE,EE but the
variables content and instancevar aren't set. The only solution I could
think of is that $this points to a wrong object, not the object that the
XML methods are called in.

Example script:
class ContentParser
    var $parser, $content = "";
    var $instancevar;

    function ContentParser()
        $this->parser = xml_parser_create();
        xml_set_object($this->parser, &$this);
        xml_set_element_handler($this->parser, "start_element",
        xml_set_character_data_handler($this->parser, "character_data");

    function parse_text ($data)
        return xml_parse ($this->parser, $data, true);

    function add_content($text)
        $this->content .= $text;

    function processing_instruction($parser, $target, $data)


    function start_element($parser, $name, $attribs)
        echo "SE<br>";
        $this->add_content("Start_element $name<br>");
        $this->instancevar = "I should be set!!!";

    function end_element($parser, $name)
        echo "EE<br>";
        $this->add_content("End element $name<br>");

    function character_data($parser, $data)

$c = new ContentParser();
$c->parse_text("<document><paragraph>Well this doesn't work.

echo $c->content; // Zip. No bonus.
echo $c->instancevar;

Am I doing something wrong or is this really a bug?
Edit bug report at:

PHP Development Mailing List <>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to