michaelham Posted July 30, 2009 Share Posted July 30, 2009 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? 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 More sharing options...
roopurt18 Posted July 30, 2009 Share Posted July 30, 2009 "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 More sharing options...
michaelham Posted July 30, 2009 Author Share Posted July 30, 2009 PERFECT Thank you. Works great now. Link to comment https://forums.phpfreaks.com/topic/168175-php-cli-problem/#findComment-887071 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.