php error throwing
i have following line of PHP code:
<?
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
if(file_exist('menu.xml'){
print("file exist");
$xml = simplexml_load_file('menu.xml');
print_r($xml);
}else{
print("cant find menu.xml");
exit('failed to open menu.xml');
}
?>
when I open this does not display anything in browser ( i Expect开发者_运维百科 error message to come). I know there is a ")" missing at the end of if statement but why don't php throw error at the first place. Once i fix that it says undefined function file_exist() ? as per php Simplexml documentation file_exist is a valid func.
You don't see anything because syntax errors prevent the script from executing entirely. Since the script isn't valid PHP, it can't be executed at all. So your display_errors
directive is never executed. Instead, the settings from php.ini regarding error handling are used, and apparently they're set to suppress all error output.
It's file_exists()
Are you sure you're not thinking of file_exists()?
http://php.net/manual/en/function.file-exists.php
Example SimpleXML code:
<?php
// The file test.xml contains an XML document with a root element
// and at least an element /[root]/title.
if (file_exists('test.xml')) {
$xml = simplexml_load_file('test.xml');
print_r($xml);
} else {
exit('Failed to open test.xml.');
}
?>
The correct function is file_exists()
not file_exist()
I guess the code isn't executed beceause of the syntax error, therefore display_errors
and error_reporting
are still configured to the system defaults.
You have to configure them in the php.ini or via php_flag
and php_value
.htaccess-directive for them to take effect in case of a syntax error.
精彩评论