Jump to content

[SOLVED] converting from php4 to php5: error in recursive function code


ungaro

Recommended Posts

I have developed a website using php 4. I'm using right now php 5.1.6, and the above code gives me error:

 

Fatal error: Call to undefined function simplexml2ISOarray() in artist.php on line 220

and that line is:

 

$r[$key] = simplexml2ISOarray($value,$attribsAsElements);

 

i think there is some recursion problem with this code, but i didn't understand why it fails to execute.

 

Your helps much appreciated,

Thanks...

Alp

 

function simplexml2ISOarray($xml,$attribsAsElements=0) {

   if (get_class($xml) == 'SimpleXMLElement') {
       $attributes = $xml->attributes();

       foreach($attributes as $k=>$v) {
           if ($v) $a[$k] = (string) $v;
       }
   
       $x = $xml;
       $xml = get_object_vars($xml);
   }
   
   if (is_array($xml)) {
       if (count($xml) == 0) return (string) $x; // for CDATA
       foreach($xml as $key=>$value) {
           $r[$key] = simplexml2ISOarray($value,$attribsAsElements);
           if (!is_array($r[$key])) $r[$key] = utf8_decode($r[$key]);
       }
       if (isset($a)) {
           if($attribsAsElements) {
               $r = array_merge($a,$r);
           } else {
               $r['@'] = $a; // Attributes
           }
       }
       return $r;
   }
   return (string) $xml;
}

no the same code is working perfectly on a php 4 setup.

 

it fails when it tries to execute itself. it's a recursive function.... i think maybe in php 5 there are some other ways for a function to call itself?? not just name; self, this or whatever, but i couldn't find it.

wow, i've found the solution.

 

i've changed the function name and all the function calls to simplexml2isoarray (all lowercase).

 

and it seems to have solved the problem.

 

i swear i did nothing else. :)

 

strange problem.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.