This code works fine when the phpfun.ini file is in place; it’s when I remove it that it does something unexpected. It displays in the browser the following warning:
( ! ) Warning: parse_ini_file(phpfun.ini) [function.parse-ini-file]: failed to open stream: No such file or directory in L:\var\www\phpfun\iniparse.php on line 25
The documentation for this function states that it returns FALSE on failure, which it does, but it also prints this warning.
Return Values
The settings are returned as an associative array on success, and FALSE on failure.
I added the try/catch block in order to handle this error on my own, but the warning persists. How should this be done so my program can handle this warning without it being displayed?
try {
if (($ini = @parse_ini_file($iniFile, true)) == false)
throw new Exception('Missing INI file: ' . $iniFile);
}
catch (Exception $e) {
die($e->getMessage());
}
…and that works (thank you), but why? I’ve come across a lot of weird things in Joomla code, trying to learn PHP. I’ve taken the w3schools PHP tutorial, but never figured out what ‘@’ does. It is very difficult to do a Google search for meta characters, like ‘@’. So, can you point me to a language reference that explains this for the beginner, please?
Surpressing errors with the @ is not a good idea. The error comes about because PHP can’t find a file, in the case of the script it can’t find the phpfun.ini file. Have you checked that it exists? Try specifying the whole path to the file.