php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #25686 XML processing instruction handling feature request (Expat)
Submitted: 2003-09-29 04:38 UTC Modified: 2003-10-02 17:17 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: bart at mediawave dot nl Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: Irrelevant OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bart at mediawave dot nl
New email:
PHP Version: OS:

 

 [2003-09-29 04:38 UTC] bart at mediawave dot nl
Description:
------------
With the XML parser module PHP currently handles processing instruction code per tag. For example: <?php echo 'Hello World' ?> is seen as an isolated chunk of code.

This doesn't work:

<XMLTAG>
  <?php for ($i = 0; $i < 4; $i++): ?>
    <XMLTAG2>
      <?php echo $i ?>
    </XMLTAG2>
  <?php endfor; ?>
</XMLTAG>

PHP handles the PHP code per <? somecode ?> tag. While in this example the code actually spans through 5 tags. But PHP doesn't recognize it this way.

Also. For my application it would be desirable if the PHP XML parser would not return the php code. The evaluation of the PHP code in the XML should be hanled by the parser. It should then only return the resulting (evaluated) XML as if it was normal XML.

Reproduce code:
---------------
<?xml version="1.0" encoding="iso-8859-1"?>
<XMLTAG>
  <?php for ($i = 0; $i < 4; $i++): ?>
    <XMLTAG2>
      <?php echo $i ?>
    </XMLTAG2>
  <?php endfor; ?>
</XMLTAG>


Expected result:
----------------
<XMLTAG>
    <XMLTAG2>
      0
    </XMLTAG2>
    <XMLTAG2>
      1
    </XMLTAG2>
    <XMLTAG2>
      2
    </XMLTAG2>
    <XMLTAG2>
      3
    </XMLTAG2>
</XMLTAG>


Actual result:
--------------
Parse error: parse error, unexpected $end in D:\php-4.3.2\PEAR\wrap_v4\dam.php(544) : eval()'d code on line 1

Parse error: parse error, unexpected T_ENDFOR in D:\php-4.3.2\PEAR\wrap_v4\dam.php(544) : eval()'d code on line 1


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-09-29 05:42 UTC] sniper@php.net
With PHP 4.3.3 I get the correct output.
Disable short-tags maybe?

 [2003-09-29 15:37 UTC] bart at mediawave dot nl
Excuse me if I was not clear enough. This "problem" occurs when parsing the specified XML file with the Expat XML functions. I get this problem with PHP 4.3.2, PHP 4.3.3 and PHP 5.0.0 beta.

You can reproduce the problem with the code on http://www.php.net/manual/en/ref.xml.php under "Example 3. External Entity Example" and using the following XML for xmltest.xml:

<?xml version="1.0" encoding="iso-8859-1"?>
<XMLTAG>
  <?php for ($i = 0; $i < 4; $i++) { ?>    
      <XMLTAG2>
      <? echo $i ?>
      </XMLTAG2>
  <?php } ?>
</XMLTAG>
 [2003-09-29 21:13 UTC] sniper@php.net
You don't need to use XML functions for this,
just include() the file..

 [2003-09-30 01:42 UTC] bart at mediawave dot nl
That could be a nice "work-around" but you don't include() XML files. You parse them with Expat. That's what Expat is for. Using include() to load an XML file would mean that I would have to use Expat to parse a PHP file that includes the XML file on the background. Unless there is no other way I think this is an ugly sollution that carries too much overhead. Especially when parsing large XML files.

The fact is that my feature request already partially exists in PHP. There is a reason for that. I just think that this feature is incomplete.
 [2003-10-02 17:17 UTC] moriyoshi@php.net
That's not what processing instructions are defined for.

Consider using xslt instead, or use some ugly workaroung such as:

<?php
ob_start();
include($something);
$buf = ob_get_clean();
xml_parse($ctxt, $buf);
?>

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 04 07:01:31 2024 UTC