PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » XML » XML_Tree » Bug #3517

getElement called without required parameter

Details

Submitted2005-02-18 14:30 UTC
Fromkermodebear at kermodebear dot org
StatusSuspended
PackageXML_Tree
PHP VersionIrrelevant
OSIrrelevant
Roadmaps(Not assigned)

Comments

[2005-02-18 14:30 UTC] kermodebear at kermodebear dot org

Description:
------------
Hello XML_Tree maintainer people,

I have run into a problem with the XML_Tree_Node code and believe it to be a bug. If it is not, please point me to some available resources where I can figure out what I am doing incorrectly.

I am currently using the most recent release of XML_Tree, 2.0.0RC2 with PHP 4.3.10. I ran into the same issue when using PHP5.0.3.

In XML_Tree_Node::addChild(), when adding an XML_Tree object as a child, XML_Tree_Node::getElement() is called without a parameter:

$this->children[$index] = $child->root->getElement();

However, XML_Tree_Node::getElement() requires a parameter; $path is not optional:

function &getElement($path)

I recommend either allowing $path to default to array(), or passing in an empty array in the $child->root->getElement() call.

Reproduce code:
---------------
<?php
require_once( 'XML/Tree.php' );
$Tree1 =& new XML_Tree();
$Tree1_Root =& $Tree1->addRoot( 'Testing' );

$Tree2 =& new XML_Tree();
$Tree2_Root =& $Tree2->addRoot( 'MoreTesting', 'MyContents' );

$Tree1_Root->addChild( $Tree2 );

echo $Tree1->get();
?>

Expected result:
----------------
<?xml version="1.0"?>
<Testing>
<MoreTesting>MyContents</MoreTesting>
</Testing>

Actual result:
--------------
Warning: Missing argument 1 for getelement() in /home/xxx/public_html/PEAR/XML/Tree/Node.php on line 444

Fatal error: Call to undefined function: get() in /home/xxx/public_html/PEAR/XML/Tree/Node.php on line 340