Page 1 of 1

passing vlaues to class function varable

Posted: Fri Nov 03, 2006 4:56 am
by itsmani1
I want to pass value to pass value to $tmp outside class how can i do so.

Code: Select all

<?PHP

	$p =& new xmlParser();
	$p->parse($data1);
        $p->tmp = "ROW";
class xmlParser
{
	var $xml_obj = null;
	var $output = array();
	var $attrs;
	function xmlParser()
	{
		$this->xml_obj = xml_parser_create();
		xml_set_object($this->xml_obj,$this);
		xml_set_character_data_handler($this->xml_obj, 'dataHandler');
		xml_set_element_handler($this->xml_obj, "startHandler", "endHandler");
	}
	
	function parse($path)
	{
		$data = $path;
		xml_parse($this->xml_obj, $data);
	}
	
	function startHandler($parser, $name, $attribs)
	{
		if($name == $tmp)  //How to pass values to this variable outside class
		{
			echo $attribs['EVENTNAME']."<BR>";
		}
	}
	
	function dataHandler($parser, $data)
	{
	}
	
	function endHandler($parser, $name)
	{
	}
}
?>

Posted: Fri Nov 03, 2006 4:59 am
by volka
http://de.php.net/language.variables.sc ... ope.global
But you could set it as object property as well.

Posted: Fri Nov 03, 2006 5:01 am
by itsmani1
just very to new classes can you please tell me how to set global

Posted: Fri Nov 03, 2006 5:04 am
by volka
Better stick with the
$p->tmp = "ROW";
attempt.

Code: Select all

if($name == $this->tmp)

Posted: Fri Nov 03, 2006 5:24 am
by itsmani1
still no luck

Code: Select all

<?PHP
	$p =& new xmlParser();
	$p->parse($data1);
	$p->tmp = 'ROW';

class xmlParser
{
	var $xml_obj = null;
	var $output = array();
	var $attrs;
	var $tmp;

	function xmlParser()
	{
		$this->xml_obj = xml_parser_create();
		xml_set_object($this->xml_obj,$this);
		xml_set_character_data_handler($this->xml_obj, 'dataHandler');
		xml_set_element_handler($this->xml_obj, "startHandler", "endHandler");
	}
	
	function parse($path)
	{
		$data = $path;
		xml_parse($this->xml_obj, $data);
	}
	
	function startHandler($parser, $name, $attribs)
	{
		if($name == $this->tmp)
		{
			echo $attribs['EVENTNAME']."<BR>";
		}
	}
	
	function dataHandler($parser, $data)
	{

	}
	
	function endHandler($parser, $name)
	{
	}
}

?>

Posted: Fri Nov 03, 2006 5:26 am
by volka
What happens? What's supposed to happen?
What did you do to find the discrepancy?


When is $p->tmp = 'ROW'; set and when is function startHandler called?

Posted: Fri Nov 03, 2006 5:58 am
by itsmani1
Its working
problem was with order

Code: Select all

$p =& new xmlParser();
 $p->tmp = 'ROW';        
 $p->parse($data1);