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 #4251

Using $this when not in object context

Details

Submitted2005-05-01 01:02 UTC
Fromabb644-spam at yahoo dot com
StatusBogus
PackageXML_Tree
PHP Version5.0.3
OSDebian Woody
Roadmaps(Not assigned)

Comments

[2005-05-01 01:02 UTC] abb644-spam at yahoo dot com

Description:
------------
Fatal error: Using $this when not in object context in /usr/local/lib/php/XML/Tree.php on line 234

using XML_Tree-2.0.0RC2

Reproduce code:
---------------
<?
require_once('XML/Tree.php');
$xt = XML_Tree::getTreeFromFile('data.xml');
if (PEAR::isError($xt)){
echo "ERROR: When loading XML File.";
return;
}
echo "OK.\n";
$xt->dump();
?>

Expected result:
----------------
OK.
<dump of data.xml>

or

PEAR_Error

Actual result:
--------------
Fatal error: Using $this when not in object context in /usr/local/lib/php/XML/Tree.php on line 234

[2005-05-02 16:26 UTC] aaron dot hawley at uvm dot edu

The documentation says the function cannot be called statically. That is the error you should see because of that specification (I'm suprised PHP let you give the function an argument at all). Try instead:

$xt = new XML_Tree('data.xml');
$tree = $ft->getTreeFromFile();
if (XML_Tree::isError($tree)) {
...

[2005-05-02 17:42 UTC] abb644-spam at yahoo dot com

Is true, this is not a bug. Thanks.

The correct code to do this is:
<?
require_once('XML/Tree.php');
$xt = new XML_Tree('data.xml');
$res = $xt->getTreeFromFile();
if (PEAR::isError($res)){
echo "ERROR: When loading XML File.";
return;
}
echo "OK.\n";
$xt->dump();
?>