php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30219 Undeclared entity error in PHP5
Submitted: 2004-09-24 13:51 UTC Modified: 2004-11-21 15:28 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: tg_surf at hotmail dot com Assigned:
Status: Closed Package: XML related
PHP Version: 5.0.1 OS: Windows 2000
Private report: No CVE-ID: None
 [2004-09-24 13:51 UTC] tg_surf at hotmail dot com
Description:
------------
When trying to parse the following xml file I get an "Undeclared entity error" in PHP5. With PHP4 it works fine.
  

Reproduce code:
---------------
The code under "Example 3. External Entity Example" at
http://www.php.net/manual/en/ref.xml.php with the following xml file:
<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
    <!ENTITY test 'http://www.hpl.hp.com/semweb/2003/query_tester#'>
    <!ENTITY rdf  'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
]>
<rdf:RDF xmlns:rdf="&rdf;" xmlns="&test;">
  <Test rdf:about="test1">
    <description>RDFS reasoner: range test, wildcard</description>
    <tbox>rdfs/tbox1.rdf</tbox>
    <data>rdfs/data1.rdf</data>
    <query>rdfs/query-res.nt</query>
    <result>rdfs/result1.rdf</result>
  </Test>
</rdf:RDF>

Expected result:
----------------
<?xml version="1.0"?>

<!DOCTYPE rdf:RDF [
    <!ENTITY test 'http://www.hpl.hp.com/semweb/2003/query_tester#'>
    <!ENTITY rdf  'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
]>
<RDF:RDF XMLNS:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#" XMLNS="http://www.hpl.hp.com/semweb/2003/query_tester#">
  <TEST RDF:ABOUT="test1">
    <DESCRIPTION>RDFS reasoner: range test, wildcard</DESCRIPTION>
    <TBOX>rdfs/tbox1.rdf</TBOX>
    <DATA>rdfs/data1.rdf</DATA>
    <QUERY>rdfs/query-res.nt</QUERY>
    <RESULT>rdfs/result1.rdf</RESULT>
  </TEST>
</RDF:RDF>

parse complete 

Actual result:
--------------
&test;&rdf;&rdf;&test;XML error: Undeclared entity error at line 7

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-12 13:13 UTC] michiel at trendserver dot nl
Also occurs on PHP 5.02
 [2004-11-19 16:47 UTC] joern_h at gmx dot net
I tested this with a current snapshot (php5-win32-200411190730.zip), entities inside attributes are now reported correctly but entities in element content are silently ignored. Here is an example document that show this behaviour:

<!DOCTYPE test [
    <!ENTITY uuml "&#252;">
]>
<test t="&uuml;">&uuml;</test>
 [2004-11-19 17:42 UTC] rrichards@php.net
Test your script with PHP 4.3 and if output different add it here with the expected output. The tests I ran with that xml snippet produced same output under 4.3 (using expat) and 5 (using libxml). In both cases the entities were not resolved in element content.
 [2004-11-20 19:01 UTC] joern_h at gmx dot net
Here is the complete script I used, with php5 (php5-win32-200411201530.zip) the entity is not resolved:

<?php

$xml = <<<HERE
<!DOCTYPE test [
    <!ENTITY uuml "&#252;">
]>
<test>&uuml;</test>
HERE;

function characters($parser, $data) {print "data: $data\n";}

$parser =& xml_parser_create('utf-8');
xml_set_character_data_handler($parser, 'characters');

if (!xml_parse($parser, $xml, true)) {
    echo xml_error_string(xml_get_error_code($parser)) . "\n";
}

xml_parser_free($parser);

?>

expected result (with php 4.3.8): data: ?
actual result: nothing

When using xml_parse_into_struct the entity is not expanded with php4 too, should I open another bug report for that?
 [2004-11-21 15:28 UTC] rrichards@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

closing as all errors here look resolved. Open new bug if something else pops up. For xml_parse_into_struct not sure if bug/feature or intended behavior.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 02:01:38 2025 UTC