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
https://forums.phpfreaks.com/topic/168175-php-cli-problem/
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
https://forums.phpfreaks.com/topic/168175-php-cli-problem/#findComment-886986
Share on other sites

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.