Jump to content

Function call doesn't work


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;
       foreach($object as $key => $value)
           $return[$key] = object2array($value);
       $var = get_object_vars($object);
           foreach($var as $key => $value)
               $return[$key] = object2array($value);
           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
Share on other sites

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


Link to comment
Share on other sites

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.

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.