php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37440 Problem assigning multiple objects with XML parser (works in PHP >= 5.1)
Submitted: 2006-05-14 20:11 UTC Modified: 2008-03-26 19:48 UTC
Votes:5
Avg. Score:4.2 ± 1.0
Reproduced:5 of 5 (100.0%)
Same Version:2 (40.0%)
Same OS:0 (0.0%)
From: kenashkov at gmail dot com Assigned:
Status: Wont fix Package: XML related
PHP Version: 4.4.2 OS: Fedora Core 4
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kenashkov at gmail dot com
New email:
PHP Version: OS:

 

 [2006-05-14 20:11 UTC] kenashkov at gmail dot com
Description:
------------
When assigning multiple times to ane variable an object which contains a XML parser, there is a problem when the xml_parse is called. The parser can not call the registered handlers.
The problem can be avoided if the variable is unset before the second call, or using $doc1 =& new xml_doc() for every assignment.

Reproduce code:
---------------
<?
class xml_doc
{
function xml_doc()
	{
	$this->res = xml_parser_create_ns();
	xml_set_object($this->res,$this);
	xml_set_element_handler($this->res,'start_element','end_element');
	}
	
function load_string($string)
	{
	xml_parse($this->res,$string);
	}
	
function start_element()
	{
	}
	
function end_element()
	{
	}
}

$str = '<?xml version="1" encoding="UTF-8" standalone="yes"?><root></root>';
$doc1 = new xml_doc();
$doc1->load_string($str);
//unset($doc1);//this solves the problem
//or using $doc1 =& new xml_doc(); in every assignment
$doc1 = new xml_doc();
$doc1->load_string($str);
?>

Expected result:
----------------
Nothing really... it is too simple to do real parsing.

Actual result:
--------------
Warning: xml_parse() [function.xml-parse.html]: Unable to call handler start_element() in file.php on line 13

Warning: xml_parse() [function.xml-parse.html]: Unable to call handler end_element() in file.php on line 13

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-22 15:22 UTC] kenashkov at gmail dot com
This can be reproduced useing the example from xml_set_object() function reference found here:
http://www.php.net/manual/en/function.xml-set-object.php

Here is the exact reproduce code:
-------------------------------------
<?php
class xml  {
   var $parser;

   function xml()
   {
       $this->parser = xml_parser_create();

       xml_set_object($this->parser, $this);
       xml_set_element_handler($this->parser, "tag_open", "tag_close");
       xml_set_character_data_handler($this->parser, "cdata");
   }

   function parse($data)
   {
       xml_parse($this->parser, $data);
   }

   function tag_open($parser, $tag, $attributes)
   {
       var_dump($parser, $tag, $attributes);
   }

   function cdata($parser, $cdata)
   {
       var_dump($parser, $cdata);
   }

   function tag_close($parser, $tag)
   {
       var_dump($parser, $tag);
   }

} // end of class xml

$xml_parser = new xml();
$xml_parser->parse("<A ID='hallo'>PHP</A>");

$xml_parser = new xml();
$xml_parser->parse("<A ID='hallo'>PHP</A>");
?>
-------------------------------------

The only modification in comparison with the given example in the manual is the second assignment of $xml_parser to a new object.

The result is:
-------------------------------------
resource(2) of type (xml) string(1) "A" array(1) { ["ID"]=>  string(5) "hallo" } resource(2) of type (xml) string(3) "PHP" resource(2) of type (xml) string(1) "A"
Warning: xml_parse() [function.xml-parse.html]: Unable to call handler tag_open() in /home/local/dev.kenashkov.com/XPATS/bug_test/t4.php on line 16

Warning: xml_parse() [function.xml-parse.html]: Unable to call handler cdata() in /home/local/dev.kenashkov.com/XPATS/bug_test/t4.php on line 16

Warning: xml_parse() [function.xml-parse.html]: Unable to call handler tag_close() in /home/local/dev.kenashkov.com/XPATS/bug_test/t4.php on line 16
-------------------------------------

It works as expected in PHP 5.1.4

The code produces the bug in PHP 4.4.2 with the following cofigure line:
-------------------------------------
'./configure' '--prefix=/web/php4.4.2' '--with-apxs2=/web/apache2-php4/bin/apxs' '--enable-bcmath=shared' '--with-bz2=shared' '--enable-calendar=shared' '--enable-ctype=shared' '--with-curl=shared' '--enable-dba=shared' '--enable-dbase=shared' '--enable-dbx=shared' '--enable-dio=shared' '--with-dom=shared' '--with-dom-xsl=shared' '--with-dom-xslt=shared' '--with-dom-exslt=shared' '--enable-exif=shared' '--with-fam=shared' '--enable-ftp=shared' '--with-gettext=shared' '--with-gmp=shared' '--with-iconv=shared' '--with-gd=shared' '--with-jpeg-dir' '--with-png-dir' '--with-xpm-dir' '--with-ttf' '--with-freetype-dir' '--enable-gd-native-ttf' '--with-ldap=shared' '--enable-mbstring=all' '--enable-mbstr-enc-trans' '--enable-mbregex' '--with-mime-magic=shared' '--with-mysql=/web/mysql-max-5.0.15-linux-i686-glibc23' '--with-ncurses=shared' '--with-openssl=shared' '--enable-overload=shared' '--enable-pcntl=shared' '--with-pgsql=shared' '--with-regex' '--enable-maintainer-zts' '--enable-sysvsem=shared' '--enable-sysvshm=shared' '--enable-sysvmsg=shared' '--enable-shmop=shared' '--enable-sockets=shared' '--enable-memory-limit' '--enable-wddx=shared' '--with-zlib=shared' '--with-mhash=shared' '--with-mcrypt=shared' '--enable-xslt=shared' '--with-xslt-sablot' '--with-mssql=shared' '--with-kerberos=shared' '--enable-yp' '--enable-fastcgi' '--with-oci8=/u01/app/oracle/product/10.1.0/Db_1'
-------------------------------------
 [2008-03-26 19:48 UTC] rrichards@php.net
We are sorry, but we can not support PHP 4 related problems anymore.
Momentum is gathering for PHP 6, and we think supporting PHP 4 will
lead to a waste of resources which we want to put into getting PHP 6
ready.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC