|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13553 $this isn't set in XML object handlers
Submitted: 2001-10-04 22:59 UTC Modified: 2002-01-14 22:56 UTC
From: phpbugs at improbable dot org Assigned:
Status: Closed Package: XML related
PHP Version: 4.0.6 OS: Mac OS X 10.1
Private report: No CVE-ID: None
 [2001-10-04 22:59 UTC] phpbugs at improbable dot org
xml_set_object() allows you to use an xml parser inside a 
class and have it call class methods instead of global 
functions. $this is not set properly within the context of 
these handlers when called by the xml parser. This can 
cause data loss (e.g. $this->variable is set by one of the 
XML handlers and disappears after the parsing is finished) 
or, if you try to call certain functions on $this such as 
gettype() or classname() php will die with a bus error:

	class ThisBug {
		var $XMLParser;
		function ThisBug() {
			$this->XMLParser = xml_parser_create();

			xml_set_object($this->XMLParser, $this);
"xmlStartElement", "xmlEndElement");
		function parse() {
			$xml = '<?xml version="1.0"?' . '><foo><bar></bar></foo>
			if (!xml_parse($this->XMLParser, $xml, true)) {
					die( sprintf("XML parse error: %s at line %d\n", 
xml_get_current_line_number($this->XMLParser) )
		function xmlStartElement($parser, $name, $attribs) {
			print "Opening $name - \$this = " . gettype($this) . "\

		function xmlEndElement($parser, $name) {
			print "Closing $name - \$this = " . gettype($this) . "\


	$CrashMe = new ThisBug();

chris@calaban:~/Development/netdiff $ php -q ThisBug.php 
Opening foo - $this = object
Opening bar - $this = object
Closing bar - $this = object
Bus error

(uname -a = Darwin 1.4 Darwin Kernel 
Version 1.4: Sun Sep  9 15:39:59 PDT 2001; root:xnu/xnu-
201.obj~1/RELEASE_PPC  Power Macintosh powerpc)

This appears to be identical to bug #12959, which was 
marked bogus with the mistaken comment "you are trying to 
use $this outside of a class so it does not work.", when 
$this was being used inside a class, as it is here. This is 
the entire point for having xml_set_object().


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-14 10:01 UTC]
Is this valid on 4.1.1?
 [2002-01-14 22:56 UTC] phpbugs at improbable dot org
It no longer crashes with 4.1.0. I'm going to test my larger XML application later this week.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Dec 03 08:03:33 2021 UTC