You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4php-dev@logging.apache.org by "Maciej Mazur (JIRA)" <ji...@apache.org> on 2010/05/19 20:37:54 UTC

[jira] Created: (LOG4PHP-117) LoggerConfiguratorIni::configure() and unexptected results from error_get_last()

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


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 ist 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.


[jira] Updated: (LOG4PHP-117) LoggerConfiguratorIni::configure() and unexptected results from error_get_last()

Posted by "Christian Grobmeier (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4PHP-117?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Christian Grobmeier updated LOG4PHP-117:
----------------------------------------

    Affects Version/s: 2.1
                           (was: 2.0)

> 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.1
>            Reporter: Maciej Mazur
>         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.


[jira] Issue Comment Edited: (LOG4PHP-117) LoggerConfiguratorIni::configure() and unexptected results from error_get_last()

Posted by "Maciej Mazur (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOG4PHP-117?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12870444#action_12870444 ] 

Maciej Mazur edited comment on LOG4PHP-117 at 5/23/10 3:15 PM:
---------------------------------------------------------------

Actually i don't think it should be thrown anything if there is no file, or file contains no properties. A warning or notice could be printed (to stderr), but there is no need to throw an exception (I belive log4j behaves like this). 


      was (Author: mamciek):
    Actually i don't think it should be thrown anything if there is no file, or file contains no properties. A warning or notice could be printed (to stdout), but there is no need to throw an exception (I belive log4j behaves like this). 

  
> 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.


[jira] Commented: (LOG4PHP-117) LoggerConfiguratorIni::configure() and unexptected results from error_get_last()

Posted by "Maciej Mazur (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOG4PHP-117?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12870444#action_12870444 ] 

Maciej Mazur commented on LOG4PHP-117:
--------------------------------------

Actually i don't think it should be thrown anything if there is no file, or file contains no properties. A warning or notice could be printed (to stdout), but there is no need to throw an exception (I belive log4j behaves like this). 


> 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.


[jira] Updated: (LOG4PHP-117) LoggerConfiguratorIni::configure() and unexptected results from error_get_last()

Posted by "Ivan Habunek (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4PHP-117?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ivan Habunek updated LOG4PHP-117:
---------------------------------

    Attachment: error_get_last_patch_v2

Here's a patch.

BTW; how do you get indented code in comments? The {code} tags used in wiki don't work. Do you use pre tags?

> 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, error_get_last_patch_v2
>
>
> 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.


[jira] Commented: (LOG4PHP-117) LoggerConfiguratorIni::configure() and unexptected results from error_get_last()

Posted by "Maciej Mazur (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOG4PHP-117?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12872180#action_12872180 ] 

Maciej Mazur commented on LOG4PHP-117:
--------------------------------------

I don't remember how i did this :) I belive a just manually added spaces

> 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, error_get_last_patch_v2
>
>
> 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.


[jira] Commented: (LOG4PHP-117) LoggerConfiguratorIni::configure() and unexptected results from error_get_last()

Posted by "Maciej Mazur (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOG4PHP-117?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12872163#action_12872163 ] 

Maciej Mazur commented on LOG4PHP-117:
--------------------------------------

The above solution is good in my opinion. It solves everything.

> 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.


[jira] Updated: (LOG4PHP-117) LoggerConfiguratorIni::configure() and unexptected results from error_get_last()

Posted by "Maciej Mazur (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4PHP-117?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Maciej Mazur updated LOG4PHP-117:
---------------------------------

    Description: 
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

  was:
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 ist 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





> 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
>         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.


[jira] Updated: (LOG4PHP-117) LoggerConfiguratorIni::configure() and unexptected results from error_get_last()

Posted by "Maciej Mazur (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4PHP-117?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Maciej Mazur updated LOG4PHP-117:
---------------------------------

    Description: 
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 ist 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




  was:
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 ist 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





> 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
>         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 ist 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.


[jira] Commented: (LOG4PHP-117) LoggerConfiguratorIni::configure() and unexptected results from error_get_last()

Posted by "Ivan Habunek (JIRA)" <ji...@apache.org>.
    [ 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.


[jira] Updated: (LOG4PHP-117) LoggerConfiguratorIni::configure() and unexptected results from error_get_last()

Posted by "Christian Grobmeier (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4PHP-117?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Christian Grobmeier updated LOG4PHP-117:
----------------------------------------

        Fix Version/s: 2.1
    Affects Version/s: 2.0
                           (was: 2.1)

> 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.


[jira] Commented: (LOG4PHP-117) LoggerConfiguratorIni::configure() and unexptected results from error_get_last()

Posted by "Christian Grobmeier (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOG4PHP-117?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12869499#action_12869499 ] 

Christian Grobmeier commented on LOG4PHP-117:
---------------------------------------------

Actually this is a pretty bad behaviour of Log4PHP. Thanks for bringing this up.
I am not sure if triggering an empty error is what we should do here.

I am also not sure if we really need the error_get_last. If we have false properties or a count of 0, then its very clear that its something wrong with the properties file. We can raise the exception without knowing the exact case. Maybe this would be enough:

throw new LoggerException("LoggerConfiguratorIni could not parse properties file: ".$url);

and dropping of trigger_error and error_get_last


What do you think? 

> 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.1
>            Reporter: Maciej Mazur
>         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.


[jira] Issue Comment Edited: (LOG4PHP-117) LoggerConfiguratorIni::configure() and unexptected results from error_get_last()

Posted by "Ivan Habunek (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOG4PHP-117?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12872154#action_12872154 ] 

Ivan Habunek edited comment on LOG4PHP-117 at 5/27/10 5:36 AM:
---------------------------------------------------------------

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:

{code}
	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);
	} 
{code}

As you proposed, a warning is issued if there are no values in the config file.

      was (Author: juice):
    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.


[jira] Commented: (LOG4PHP-117) LoggerConfiguratorIni::configure() and unexptected results from error_get_last()

Posted by "Ivan Habunek (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOG4PHP-117?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12892811#action_12892811 ] 

Ivan Habunek commented on LOG4PHP-117:
--------------------------------------

Committed in revision 979738.

> 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, error_get_last_patch_v2
>
>
> 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.


[jira] Resolved: (LOG4PHP-117) LoggerConfiguratorIni::configure() and unexptected results from error_get_last()

Posted by "Ivan Habunek (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4PHP-117?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ivan Habunek resolved LOG4PHP-117.
----------------------------------

    Resolution: Fixed

> 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, error_get_last_patch_v2
>
>
> 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.


[jira] Updated: (LOG4PHP-117) LoggerConfiguratorIni::configure() and unexptected results from error_get_last()

Posted by "Maciej Mazur (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4PHP-117?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Maciej Mazur updated LOG4PHP-117:
---------------------------------

    Attachment: error_get_last_patch

I attached patch solving this issue

> 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
>         Attachments: error_get_last_patch
>
>
> 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 ist 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.