Jump to content

Recommended Posts

Hi everyone,

 

I have stared at the following problem for so long that I may be missing something very elementary; I was hoping somebody might spot it.

 

I wrote a piece of code which includes a call to a function someone else wrote. They are in two different files: "File.php" (which I wrote) and "Functions1.php." The latter, Functions1.php, contains the fuction the other guy wrote.

 

When I launch File.php to the browser, I get the following message:

Warning: get_object_vars() expects parameter 1 to be object, string given in C:\Program Files\xampp\htdocs\dev\Functions1.php on line 20

 

Here is the pertinent part of File.php:

require_once ("Functions1.php");
//////////////////////////////////////////////////////////

$lastxml = basename('c:/program files/xampp/htdocs/dev/xmlfilename.xml');
$output= simplexml_load_file($lastxml);
   $rr = object2array($output);
   $fdate = getdatafromfilename($lastxml);
   $fversion = getdatafromfilename($lastxml,1);
   $generated_date = trim($rr['IMODocHeader']['CreatedAt']);
   $generated_date = str_replace("T"," ",$generated_date);

///////////  Database Settings  //////////////
   $db_hostname = "localhost";
   $db_name = "db1";
   $db_username = "jacksmith";
   $db_password = "password1";
   $cxn = mysql_connect($db_hostname, $db_username, $db_password);
/////////////////////////////////////////////

$insert2sourceinfo2 =   "insert into sourceinfo2
                  (xmlname, filedate, version, generated)
                  VALUES ('$lastxml', '$fdate', '$fversion', '$generated_date')";
                  mysql_query($insert2sourceinfo2, $cxn);
$lastSid = mysql_insert_id();

 

And here's the code for the function "object2array" in the file Functions1.php:

// converts the xml file into a php object;
function object2array($object)
{
   $return = NULL;
     
   if(is_array($object))
   {
       foreach($object as $key => $value)
           $return[$key] = object2array($value);
   }
   else
   {
       $var = get_object_vars($object);
         
       if($var)
       {
           foreach($var as $key => $value)
               $return[$key] = object2array($value);
       }
       else
           return strval($object);
   }

   return $return;
}

 

The variable $lastxml outputs properly when I execute print_r($lastxml), and the variables $fdate and $fversion also output properly.

 

Any ideas? Thanks!

Link to comment
https://forums.phpfreaks.com/topic/192809-function-call-doesnt-work/
Share on other sites

You already have an existing thread for this problem. Don't start another one. That just looses the history of how you got to this point and what has already been tried, which wastes time for those who already tried to help and those who would.

sorry, I'm not trying to waste anyone's time. I noticed my earlier thread had gone to page 2 of the previous forum, which gives me to believe it will fall off the radar. Also I felt I had not explained it properly initially; plus I realized I should have posted it to this one in the first place.

 

 

If you have additional information or clarification to add to a thread, add a post in that thread.

 

You can 'BUMP' existing threads -

 

Users should not "bump" topics that are still on the first page of the forums. If you bump, you must provide additional information. If you resort to bumping, chances are your question needs to be re-thought and re-described

 

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.