[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

I need help with php!



As many of you know, I've been working on a webpage in php.  Right now I am
stumped by a bug and have spent about 4 hours already on it.  It is likely
that the problem is quite simple but my eyes just can't see it so I am going
to post my problem up here to see if anyone else can see what's wrong.

The file that I'm attaching to this email is called xml.php
You must first have the php4-xml installed and restart apache after editing
php.ini accordingly.
You need to write a simple php script to use it, like:

<?php

require "xml.php";

$foo = new xml("test.xml");

?>

where test.xml is a simple xml document such as:

<?xml version="1.0"?>

<main>
 <sub>
  <content>bar</content>
 </sub>
</main>

You will find my problem on about line 100.

It is in my class xml_tree in the functions add_node & set_node.
set_node appears to work just fine, but add_node does something wrong.
Eache method brings the class variable tree ($this->tree) into its local
scope as the variable current ($current = $this->tree;).  Without executing
any other code, ie:

function add_node($path)
{
   $current = $this->tree;

   /* there is code here but even when commeted out this still occurs! */

   $current->add_sibling($path[count($path)]);
}

function set_node($path,$value)
{
  $current = $this->tree;

  /* this function behaves properly */

  $sibling = $current->return_sibling($path[count($path)]);
  $sibling->set($value);
}

Withous executing any other code the value seems to change!  The function
will use a object other than $this->tree unless I change the $current below
to $this->tree even though current is already set to $this->tree,
then it uses the correct object, but that isn't a solution
becuase I need it to be able to go into the tree and not make the whole thing
linear.  I also figured if it was something directly with this code it would
happen to both functions but it doesn't.  I've looked through the rest of the
code and there doesn't seem to be anything that would be messing with the
variables in this class.

*PLEASE HELP*

-- 
/-------------------------------------------------\
|Barry J Dmytro............dmytro@xxxxxxxxxxxxxxxx|
|badcherry................http://www.badcherry.org|
|job5_20.........................job5_20@xxxxxxxxx|
|jobbd.....................................AIM UID|
|job5_20...........................Yahoo Messenger|
|94626793...................................ICQ ID|
|job5_20@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ID|
|-------------------------------------------------|
|The primary purpose of the DATA statement is to .|
|give names to constants; instead of referring to.|
|pi as 3.141592653589793 at every appearance, the.|
|variable PI can be given that value with a DATA .|
|statement and used instead of the longer form of.|
|the constant. This also simplifies modifying the.|
|program, should the value of pi change...........|
|..............FORTRAN manual for Xerox Computers.|
\-------------------------------------------------/

Attachment: xml.php
Description: application/httpd-php