Jump to content

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


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.

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.