Jump to content

PHP CLI Problem


michaelham

Recommended Posts

I am having a problem when trying to execute a php script using the command line interface in windows.

 

The script executes successfully in Internet Explorere but when I run it in CLI I get the following message.

 

"Trying to get property of non object on line 28".

Here is the code snippet.  The count() function is on line 28. Any ideas?

:shrug:

if(file_exists("METADATA-TABLE.xml"))
{
$xml = simplexml_load_file("C:\greta05\bin\METADATA-TABLE.xml");
echo "<br />File Exists and loaded<br />";

//print_r($xml);
//$title = 'Hello';
$p_cnt = count($xml->METADATA->{'METADATA-TABLE'});

echo "<br />There are $p_cnt tables in this metadata.<br />";

Link to comment
Share on other sites

"Trying to get property of non object" means you are using -> on a variable that is not an object.  Since you are using $xml->METADATA that means $xml is not an object like you expected it to be.

 

Why wouldn't it be an object you ask?  Because simplexml_load_file() probably returns FALSE when it fails.

 

Why would simplexml_load_file() fail you ask?  Because the file you told it to open doesn't exist.

 

And why doesn't it exist?  Because you didn't escape your backslashes in the string.

 

$xml = simplexml_load_file("C:\\greta05\\bin\\METADATA-TABLE.xml");

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.

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.