[
https://issues.apache.org/jira/browse/LOG4PHP-117?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12872154#action_12872154
]
Ivan Habunek commented on LOG4PHP-117:
--------------------------------------
I think you're going about this the wrong way. parse_ini_file() returns FALSE
when an error occured which can then be fetched by error_get_last(). Therefore,
error_get_last should only be called if parse_ini_file returns FALSE. It should
not be called when it returns an empty array. An empty array is returned when
you successfully parse an empty config file.
I propose the following solution:
public function configure(LoggerHierarchy $hierarchy, $url = '') {
$properties = @parse_ini_file($url);
if ($properties === false) {
$error = error_get_last();
throw new LoggerException("LoggerConfiguratorIni: Error
parsing configuration file: ".$error['message']);
}
if (count($properties) == 0) {
trigger_error("LoggerConfiguratorIni: Configuration
file is empty.", E_USER_WARNING);
}
return $this->doConfigureProperties($properties, $hierarchy);
}
As you proposed, a warning is issued if there are no values in the config file.
> LoggerConfiguratorIni::configure() and unexptected results from
> error_get_last()
> --------------------------------------------------------------------------------
>
> Key: LOG4PHP-117
> URL: https://issues.apache.org/jira/browse/LOG4PHP-117
> Project: Log4php
> Issue Type: Bug
> Components: Code
> Affects Versions: 2.0
> Reporter: Maciej Mazur
> Fix For: 2.1
>
> Attachments: error_get_last_patch
>
>
> This apply to src/main/php/configurators/LoggerConfiguratorIni.php
> If you invoke LoggerConfiguratorIni::configure() after there was any notice
> or warning in your PHP script, then LoggerConfiguratorIni will throw an
> exception even if there is no need (propably terminating execution)
> 284 public function configure(LoggerHierarchy $hierarchy, $url =
> '') {
> 285 $properties = @parse_ini_file($url);
> 286 if ($properties === false || count($properties) == 0) {
> 287 $error = error_get_last();
> 288 throw new LoggerException("LoggerConfiguratorIni:
> ".$error['message']);
> 289 }
> 290 return $this->doConfigureProperties($properties,
> $hierarchy);
> 291 }
> In line 287 it is checked if there was any error triggered by function
> parse_ini_file(). Unfortunately function error_get_last() doesn't return an
> error triggered by execution of the last function. It returnes an error that
> is most recent in global, even if it was already catched and taken care of.
> This is because there is no way to reset the state of the last error. It
> returns always the last triggered error.
> (http://www.php.net/manual/en/function.error-get-last.php#83608)
> I attached the patch that "solves" this by triggering an empty error before
> parse_ini_file(), and the it is checked if the error has an empty message:
> public function configure(LoggerHierarchy $hierarchy, $url = '') {
> @trigger_error('');
> $properties = @parse_ini_file($url);
> if ($properties === false || count($properties) == 0) {
> $error = error_get_last();
> if ($error['message'] != '') {
> throw new
> LoggerException("LoggerConfiguratorIni: ".$error['message']);
> }
> }
> return $this->doConfigureProperties($properties, $hierarchy);
> }
> This not very pretty but it works
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.