Uploaded image for project: 'Log4php'
  1. Log4php
  2. LOG4PHP-117

LoggerConfiguratorIni::configure() and unexptected results from error_get_last()

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.0
    • 2.1.0
    • Code
    • None

    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

      Attachments

        1. error_get_last_patch
          0.9 kB
          Maciej Mazur
        2. error_get_last_patch_v2
          1.0 kB
          Ivan Habunek

        Activity

          mamciek Maciej Mazur created issue -
          mamciek Maciej Mazur made changes -
          Field Original Value New Value
          Attachment error_get_last_patch [ 12444968 ]
          mamciek Maciej Mazur made changes -
          Description 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 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


          mamciek Maciej Mazur made changes -
          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


          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
          cgrobmeier cgrobmeier made changes -
          Affects Version/s 2.0 [ 12313916 ]
          Affects Version/s 2.1 [ 12313917 ]
          cgrobmeier cgrobmeier made changes -
          Fix Version/s 2.1 [ 12313917 ]
          Affects Version/s 2.0 [ 12313916 ]
          Affects Version/s 2.1 [ 12313917 ]
          juice Ivan Habunek made changes -
          Attachment error_get_last_patch_v2 [ 12445636 ]
          juice Ivan Habunek made changes -
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Resolved [ 5 ]
          juice Ivan Habunek made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          iroh Chris Wells made changes -
          Workflow classic default workflow [ 12511294 ] Classic - editable closed [ 14044045 ]
          iroh Chris Wells made changes -
          Workflow Classic - editable closed [ 14044045 ] classic default workflow [ 14044180 ]
          iroh Chris Wells made changes -
          Workflow classic default workflow [ 14044180 ] Classic - editable closed [ 14044580 ]
          iroh Chris Wells made changes -
          Admin-Comment-Bulk Update Author [ Christian Grobmeier ] [ Christian Grobmeier ]
          iroh Chris Wells made changes -
          Workflow Classic - editable closed [ 14044580 ] classic default workflow [ 14044808 ]

          People

            Unassigned Unassigned
            mamciek Maciej Mazur
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: