Jump to content


Photo

Cannot redeclare getchildren()


  • Please log in to reply
1 reply to this topic

#1 Kittyfuzz

Kittyfuzz
  • New Members
  • Pip
  • Newbie
  • 1 posts
  • LocationPittsburgh, Pa.

Posted 02 October 2006 - 01:00 AM

Hi.

I can't seen to resolve this error

Fatal error: Cannot redeclare getchildren() (previously declared in /home/extreme/public_html/modules/Radio/2/common/xml.php:3) in /home/extreme/public_html/modules/Radio/common/xml.php on line 3

/common/xml.php
Code:
<?php

//XML handling routines
  function GetChildren($vals, &$i)
{
  while($i < count($vals))
  {

    switch ($vals[$i]['type'])
      {
        //case 'cdata':
		case 'complete' :
		if(isset($vals[$i]['attributes']))
		{
			$value = array("attributes" => $vals[$i]['attributes'],
			      "value" => $vals[$i]['value']);
		}
		else
		{
			$value = array("value" => $vals[$i]['value']);
		}
		 $name = $vals[$i]['tag'];
         $children["$name"][] = $value; 
		 
		break;
		
		case 'open'     : 
		 $siblings = GetChildren($vals, ++$i);
		if(isset($vals[$i]['attributes']))
		  {
			$siblings['attributes'] = $vals[$i]['attributes'];
		  }
		 
		 $name = $vals[$i]['tag'];
         $children["$name"][] = $siblings;
		 
		 /*
		 array_push($children,
		  array("attributes" => $vals[$i]['attributes'],
		  "children" => GetChildren($vals, ++$i))
		  );
		  */
		break;
		
		case 'close'    :
		 return $children;
		break;
		
		default : 	 
		 echo "XML error, Unsupported tag type: " . $vals[$i]['type'] . "<br>";
	 }
	
	$i++;
  }
  
 return $children; 
}
  
  function GetXMLTree($data, $uppercase = 1)
  {
    $p = xml_parser_create();
    xml_parser_set_option($p, XML_OPTION_SKIP_WHITE, 1);
	xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, $uppercase);
	
    xml_parse_into_struct($p, $data, $vals, $index);
    xml_parser_free($p);

    $tree = array();
    $i = 0;

    $tree = GetChildren($vals, $i);
	
    return $tree;
  }
  
//######################################################  
//######################################################
  
function CompackTree($data)
{

 reset($data);
 while(list($key, $value) = each($data))
 {
 
  if(is_array($value))
  {
  
   //SPECIAL HANDLING
   //Make Attributes the Values if value empty
  if(isset($value['attributes']))
   if(is_array($value['attributes']))
    if(!isset($value['value']))
	 {
	   $leaf["$key"] = $value['attributes'];
	   continue;
	 }
   
   $c = count($value);
   
   if($c>1)
   {
    //REMOVE empty Attributes if Value is valid
    if(!((isset($value['attributes'])) && (is_array($value['attributes']))) && (isset($value['value'])))
	  $leaf["$key"] = $value['value'];
	 else
      $leaf["$key"] = CompackTree($value);
   }
   else
   {
     $temp = $value[0];
	 //REMOVE empty Attributes if Value is valid
	if(isset($temp['attributes']))
	{
	 if(!is_array($temp['attributes']) && (isset($temp['value'])))
	  $leaf["$key"] = $temp['value'];
	 else $leaf["$key"] = CompackTree($temp);
	} else if(isset($temp['value']))
		$leaf["$key"] = $temp['value'];
		else $leaf["$key"] = CompackTree($temp);
   }
   
  } 
  else
   $leaf["$key"] = $value;
	 
 }	// while loop
 
 return $leaf;
}
  
  
function XMLToArray($data, $uppercase = 1)
{
 $tree = GetXMLTree($data, $uppercase);
 return CompackTree($tree);
}

function XML2Array($data, $uppercase = 1)
{
 return XMLToArray($data, $uppercase);
}

function XML2Arr($data, $uppercase = 1)
{
 return XMLToArray($data, $uppercase);
}

//######################################################
//######################################################
function ChildKeyIsNum($data)
{
  if(!is_array($data))
   return false;
   
  reset($data);
  list($key, $value) = each($data);
  if(is_numeric($key))
   return true;
  else
   return false;
}

function MakeAttr($data)
{
 if(!is_array($data))
  return "";

 $attr = " ";
 reset($data);
 while(list($key, $value) = each($data)){
   $attr .= " $key=\"$value\"";	 
 }	// while loop

 return $attr;
}

function ArrayToXML($data, $parent = "")
{
 if(empty($parent))
  $xml = '<?xml version="1.0"?>';
 else 
  $xml = "";
  
  reset($data);
  while(list($key, $value) = each($data))
  {
   $attr = "";
   
   if(is_numeric($key))
   {
     $key = $parent;
	 
	 if(!empty($value['attributes']))
   	  $attr = MakeAttr($value['attributes']);
     unset($value['attributes']);
   };
    
	
   if(ChildKeyIsNum($value))
 	$xml .= ArrayToXML($value,$key);
   else if(is_array($value))
    {
      $xml .= "<$key$attr>";
       $xml .= ArrayToXML($value,$key);
	  $xml .= "</$key$attr>";
    }
     else
       $xml .= "<$key$attr>$value</$key>";
  }//while
  
 return $xml;  
}

function Array2XML($data, $parent = "")
{
 return ArrayToXML($data, $parent);
}

function Arr2XML($data, $parent = "")
{
 return ArrayToXML($data, $parent);
}
//######################################################
//######################################################
  

function Keys2Lower($a)
{
 if(!is_array($a))
  return $a;
 
 unset($res);
 
 reset($a);
 while(list($key, $value) = each($a)){

  if(is_array($value))
   $res[strtolower($key)] = Keys2Lower($value);
  else
   $res[strtolower($key)] = $value;
	 
 }	// while loop
 
 return $res;
}

function XMLheader()
{
 header("Content-type: text/xml");
}

function EmptyNodeCleanUp(&$data)
{
 while(list($key, $val) = each($data)){
  if(is_array($val))
   $data[$key] = "";
 }	// while loop
}

function echoXML($xml)
{
  XMLheader();
  
  if(is_array($xml))
   echo Array2XML($xml);
  else
   echo $xml;
}

?>
============================================================================

/common/2/xml.php
Code:
<?php
//XML handling routines
function GetChildren($vals, &$i)
{
  while($i < count($vals))
  {

    switch ($vals[$i]['type'])
      {
        //case 'cdata':
		case 'complete' :
		if(isset($vals[$i]['attributes']))
		{
			$value = array("attributes" => $vals[$i]['attributes'],
			      "value" => $vals[$i]['value']);
		}
		else
		{
			$value = array("value" => $vals[$i]['value']);
		}
		 $name = $vals[$i]['tag'];
         $children["$name"][] = $value; 
		 
		break;
		
		case 'open'     : 
		 $siblings = GetChildren($vals, ++$i);
		if(isset($vals[$i]['attributes']))
		  {
			$siblings['attributes'] = $vals[$i]['attributes'];
		  }
		 
		 $name = $vals[$i]['tag'];
         $children["$name"][] = $siblings;
		 
		 /*
		 array_push($children,
		  array("attributes" => $vals[$i]['attributes'],
		  "children" => GetChildren($vals, ++$i))
		  );
		  */
		break;
		
		case 'close'    :
		 return $children;
		break;
		
		default : 	 
		 echo "XML error, Unsupported tag type: " . $vals[$i]['type'] . "<br>";
	 }
	
	$i++;
  }
  
 return $children; 
}
  
  function GetXMLTree($data, $uppercase = 1)
  {
    $p = xml_parser_create();
    xml_parser_set_option($p, XML_OPTION_SKIP_WHITE, 1);
	xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, $uppercase);
	
    xml_parse_into_struct($p, $data, $vals, $index);
    xml_parser_free($p);

    $tree = array();
    $i = 0;

    $tree = GetChildren($vals, $i);
	
    return $tree;
  }
  
//######################################################  
//######################################################
  
function CompackTree($data)
{

 reset($data);
 while(list($key, $value) = each($data))
 {
 
  if(is_array($value))
  {
  
   //SPECIAL HANDLING
   //Make Attributes the Values if value empty
  if(isset($value['attributes']))
   if(is_array($value['attributes']))
    if(!isset($value['value']))
	 {
	   $leaf["$key"] = $value['attributes'];
	   continue;
	 }
   
   $c = count($value);
   
   if($c>1)
   {
    //REMOVE empty Attributes if Value is valid
    if(!((isset($value['attributes'])) && (is_array($value['attributes']))) && (isset($value['value'])))
	  $leaf["$key"] = $value['value'];
	 else
      $leaf["$key"] = CompackTree($value);
   }
   else
   {
     $temp = $value[0];
	 //REMOVE empty Attributes if Value is valid
	if(isset($temp['attributes']))
	{
	 if(!is_array($temp['attributes']) && (isset($temp['value'])))
	  $leaf["$key"] = $temp['value'];
	 else $leaf["$key"] = CompackTree($temp);
	} else if(isset($temp['value']))
		$leaf["$key"] = $temp['value'];
		else $leaf["$key"] = CompackTree($temp);
   }
   
  } 
  else
   $leaf["$key"] = $value;
	 
 }	// while loop
 
 return $leaf;
}
  
  
function XMLToArray($data, $uppercase = 1)
{
 $tree = GetXMLTree($data, $uppercase);
 return CompackTree($tree);
}

function XML2Array($data, $uppercase = 1)
{
 return XMLToArray($data, $uppercase);
}

function XML2Arr($data, $uppercase = 1)
{
 return XMLToArray($data, $uppercase);
}

//######################################################
//######################################################
function ChildKeyIsNum($data)
{
  if(!is_array($data))
   return false;
   
  reset($data);
  list($key, $value) = each($data);
  if(is_numeric($key))
   return true;
  else
   return false;
}

function MakeAttr($data)
{
 if(!is_array($data))
  return "";

 $attr = " ";
 reset($data);
 while(list($key, $value) = each($data)){
   $attr .= " $key=\"$value\"";	 
 }	// while loop

 return $attr;
}

function ArrayToXML($data, $parent = "")
{
 if(empty($parent))
  $xml = '<?xml version="1.0"?>';
 else 
  $xml = "";
  
  reset($data);
  while(list($key, $value) = each($data))
  {
   $attr = "";
   
   if(is_numeric($key))
   {
     $key = $parent;
	 
	 if(!empty($value['attributes']))
   	  $attr = MakeAttr($value['attributes']);
     unset($value['attributes']);
   };
    
	
   if(ChildKeyIsNum($value))
 	$xml .= ArrayToXML($value,$key);
   else if(is_array($value))
    {
      $xml .= "<$key$attr>";
       $xml .= ArrayToXML($value,$key);
	  $xml .= "</$key$attr>";
    }
     else
       $xml .= "<$key$attr>$value</$key>";
  }//while
  
 return $xml;  
}

function Array2XML($data, $parent = "")
{
 return ArrayToXML($data, $parent);
}

function Arr2XML($data, $parent = "")
{
 return ArrayToXML($data, $parent);
}
//######################################################
//######################################################
  

function Keys2Lower($a)
{
 if(!is_array($a))
  return $a;
 
 unset($res);
 
 reset($a);
 while(list($key, $value) = each($a)){

  if(is_array($value))
   $res[strtolower($key)] = Keys2Lower($value);
  else
   $res[strtolower($key)] = $value;
	 
 }	// while loop
 
 return $res;
}

function XMLheader()
{
 header("Content-type: text/xml");
}

function EmptyNodeCleanUp(&$data)
{
 while(list($key, $val) = each($data)){
  if(is_array($val))
   $data[$key] = "";
 }	// while loop
}

function echoXML($xml)
{
  XMLheader();
  
  if(is_array($xml))
   echo Array2XML($xml);
  else
   echo $xml;
}

?>
This is for request and dedication script on my radio site.

Thanks for any help :)

MOD EDIT : Code tags added. Please use them in future.


#2 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 02 October 2006 - 01:31 AM

both files have the same function(s)

/common/xml.php
/common/2/xml.php

the above (2) files have the same function GetChildren(), in fact they are the same file!

Change your include call to only use one of them and use include_once() or require_once() to only include the file once, if by chance it could be included by another script!

me!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users