function inside function, will it work?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

function inside function, will it work?

Post by itsmani1 »

Code: Select all

<?PHP
function paxml($data)
{
	function startElement($parser, $name, $attrs)
	{
		if($name == "ROW")
		{
			echo "Hay";		
		}
	}

	echo "Hay";
	exit;

	function endElement($parser, $name)
	{
	}	
	function characterData($parser, $name)
	{
	}
	$xml_parser = xml_parser_create();
	xml_set_element_handler($xml_parser, "startElement", "endElement");
	xml_set_character_data_handler($xml_parser, "characterData");
	
	xml_parse($xml_parser, $data);
	xml_parser_free($xml_parser);
}
?>
Its not working
gunman
Forum Newbie
Posts: 10
Joined: Fri Aug 26, 2005 12:07 pm

Answer

Post by gunman »

You could insert function in function, but you should describe each function body separate. Something like this

Code: Select all

function f1(params)
{
  body1
}

function f2(params)
{
  body2
}

..

function fn(params)
{
  bodyn
}

function whole(params)
{
  f1(param);
  f2(param);
  ..
  fn(param);
}
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Re: function inside function, will it work?

Post by jmut »

itsmani1 wrote:

Code: Select all

<?PHP
function paxml($data)
{
	function startElement($parser, $name, $attrs)
	{
		if($name == "ROW")
		{
			echo "Hay";		
		}
	}

	echo "Hay";
	exit;

	function endElement($parser, $name)
	{
	}	
	function characterData($parser, $name)
	{
	}
	$xml_parser = xml_parser_create();
	xml_set_element_handler($xml_parser, "startElement", "endElement");
	xml_set_character_data_handler($xml_parser, "characterData");
	
	xml_parse($xml_parser, $data);
	xml_parser_free($xml_parser);
}
?>
Its not working
this does not produce any error? what exactly is wrong?
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

tried this but still not working

Code: Select all

<?PHP
	function startElement($parser, $name, $attrs)
	{
		if($name == "ROW")
		{
			echo "Hay";		
		}
	}


	function endElement($parser, $name)
	{
	}	
	function characterData($parser, $name)
	{
	}
	
function paxml($data)
{

	$xml_parser = xml_parser_create();
	xml_set_element_handler($xml_parser, "startElement", "endElement");
	xml_set_character_data_handler($xml_parser, "characterData");

	echo "Hay";
	exit;
	
	xml_parse($xml_parser, $data);
	xml_parser_free($xml_parser);
}
?>

I can't see any error, any suggestion how i can see errors
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

itsmani1 wrote:tried this but still not working

Code: Select all

<?PHP
	function startElement($parser, $name, $attrs)
	{
		if($name == "ROW")
		{
			echo "Hay";		
		}
	}


	function endElement($parser, $name)
	{
	}	
	function characterData($parser, $name)
	{
	}
	
function paxml($data)
{

	$xml_parser = xml_parser_create();
	xml_set_element_handler($xml_parser, "startElement", "endElement");
	xml_set_character_data_handler($xml_parser, "characterData");

	echo "Hay";
	exit;
	
	xml_parse($xml_parser, $data);
	xml_parser_free($xml_parser);
}
?>

I can't see any error, any suggestion how i can see errors
display_errors should be on. error_reporting (E_ALL)
Post Reply