PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » XML » XML_Parser » Bug #6078

func-mode does not handle all allowed letters in tags

Details

Submitted2005-11-26 15:07 UTC
Fromelandril at gmail dot com
Assignedschst
StatusClosed
PackageXML_Parser
PHP Version4.3.11
OSLinux
Roadmaps(Not assigned)

Comments

[2005-11-26 15:07 UTC] elandril at gmail dot com

Description:
------------
The XML_Parser in func-mode cannot handle any tags containing the following letters '-' and ':'!
In the code there is a str_replace converting any '.' into an '_', but the two chars mentioned above are not converted.
XML allows tags using the schema
TagName ::= (Letter | '_' | ':')(NameChar)*
NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | OtherChars

Thus the str_replace (and the strchr used in the enclosing if) should be extended to convert at least '-' and ':'.

e.g.
OLD: str_replace('.', '_', $func)
NEW: str_replace( array('.', '-', '_'), '_', $func)

The documentation should be updated to include the replacement for these characters.

Test script:
---------------
$p =& new myParser;
$p->setmode('func');
$p->setInputFile('myfile.xml);
$p->parse();

myfile.xml:
<?xml version="1.0" ?>
<root-elem>
<my-tag>
</my-tag>
<tag:another>
</tag:another>
</root-elem>

Expected result:
----------------
the following function should be called:
$p->xmltag_root_elem
$p->xmltag_my_tag
$p->xmltag_my_tag_
$p->xmltag_tag_another
$p->xmltag_tag_another_
$p->xmltag_root_elem_

Actual result:
--------------
Multiple warnings of the type:
Warning: call_user_func(xmltag_my-tag): First argument is expected to be a valid callback in ...

Reason: PHP doesn't support '-' and ':' in function names.