Zend Framework

Zend_Config_Ini doesn't restore error handler, Zend_Loader::isReadable throw a Exception

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.6.0RC1, 1.6.0RC2
  • Fix Version/s: 1.6.0
  • Component/s: Zend_Config
  • Labels:
    None

Description

Zend_Config_ini use a error handler for "convert any warnings into exceptions"

Zend_Config_Ini.php / __construct / LOC: 108
$old_error_handler = set_error_handler(array('Zend_Config_Ini', 'parseIniFileErrorHandler'));
        $iniArray = parse_ini_file($filename, true); // convert any warnings into exceptions
        restore_error_handler();

But apparently the function restore_error_handler doesn't works good, because the next use of Zend_Loader::isReadable throws an exception.

For example:

<?php

  include_once ('Zend/Loader.php');
        include_once ('Zend/Config/Ini.php');

        try {
                $config = new Zend_Config_Ini ('errorini', 'errorsection');
        } catch (Exception $e) {
                //Whoa! No error!
        }

        Zend_Loader::isReadable ('errorfile'); // Doesn't returns boolean, instead throws a Zend_Config_Exception

Issue Links

Activity

Hide
julien PAULI added a comment -

Ok I got it.
restore_error_handler() should be used in the parseIniFileErrorHandler(), like this :

public function parseIniFileErrorHandler(....)
{
     require_once 'Zend/Config/Exception.php';
     restore_error_handler();
     throw new Zend_Config_Exception($errstr);
}

But this seems to bug as well, and seems to be a PHP bug ( or feature ). (PHP 5.2.6)
– restore_error_handler() looks like to be ignored while written in a error handler callback function –

To fix the bug, set_error_handler($oldHandler) works, like this :

public function parseIniFileErrorHandler(....)
{
     require_once 'Zend/Config/Exception.php';
     set_error_handler($this->old_error_handler);
     throw new Zend_Config_Exception($errstr);
}

Rob, what do you think about that ?

Show
julien PAULI added a comment - Ok I got it. restore_error_handler() should be used in the parseIniFileErrorHandler(), like this :
public function parseIniFileErrorHandler(....)
{
     require_once 'Zend/Config/Exception.php';
     restore_error_handler();
     throw new Zend_Config_Exception($errstr);
}
But this seems to bug as well, and seems to be a PHP bug ( or feature ). (PHP 5.2.6) – restore_error_handler() looks like to be ignored while written in a error handler callback function – To fix the bug, set_error_handler($oldHandler) works, like this :
public function parseIniFileErrorHandler(....)
{
     require_once 'Zend/Config/Exception.php';
     set_error_handler($this->old_error_handler);
     throw new Zend_Config_Exception($errstr);
}
Rob, what do you think about that ?
Hide
julien PAULI added a comment -

I found it : http://bugs.php.net/bug.php?id=31675 ; it's a feature.

Show
julien PAULI added a comment - I found it : http://bugs.php.net/bug.php?id=31675 ; it's a feature.
Hide
Matthew Weier O'Phinney added a comment -

Julien – can this issue be closed, then?

Show
Matthew Weier O'Phinney added a comment - Julien – can this issue be closed, then?
Hide
julien PAULI added a comment -

Well, I can fix it if needed

Show
julien PAULI added a comment - Well, I can fix it if needed
Hide
Rob Allen added a comment -

Sorry, was on holiday.

Julien, if you can fix sooner than I can, please do so!

Rob...

Show
Rob Allen added a comment - Sorry, was on holiday. Julien, if you can fix sooner than I can, please do so! Rob...
Hide
julien PAULI added a comment -

Ok I patch that next week

Show
julien PAULI added a comment - Ok I patch that next week
Hide
julien PAULI added a comment -

r11107 is the fix

Show
julien PAULI added a comment - r11107 is the fix
Hide
Rob Allen added a comment -

Thanks Julien!

For reference, the fix on the release-1.6 branch is r11108.

Regards,

Rob...

Show
Rob Allen added a comment - Thanks Julien! For reference, the fix on the release-1.6 branch is r11108. Regards, Rob...
Hide
Alexander Veremyev added a comment -

Used solution corrupts error handlers stack.

E.g. source error stack:
-------------------------------------
<system error handler>
...
<latest user defined error handler>
----------------------------
will be translated into:
-------------------------------------
<system error handler>
...
<latest user defined error handler>
<Zend_Config object->_loadFileErrorHandler()>
<latest user defined error handler>
----------------------------
instead of original state.

I'm going to fix it.

Show
Alexander Veremyev added a comment - Used solution corrupts error handlers stack. E.g. source error stack: ------------------------------------- <system error handler> ... <latest user defined error handler> ---------------------------- will be translated into: ------------------------------------- <system error handler> ... <latest user defined error handler> <Zend_Config object->_loadFileErrorHandler()> <latest user defined error handler> ---------------------------- instead of original state. I'm going to fix it.
Hide
Alexander Veremyev added a comment -

Fixed for the trunk and release-1.6 branch (r11165 and r11166).

Show
Alexander Veremyev added a comment - Fixed for the trunk and release-1.6 branch (r11165 and r11166).
Hide
Alexander Veremyev added a comment -

issue still produces unit tests problems (see ZF-4139)

Show
Alexander Veremyev added a comment - issue still produces unit tests problems (see ZF-4139)
Hide
Alexander Veremyev added a comment -

Problem is actually fixed now, but it de-masked another problem (see ZF-4139).

Show
Alexander Veremyev added a comment - Problem is actually fixed now, but it de-masked another problem (see ZF-4139).
Hide
Alexander Veremyev added a comment -

Done.

Show
Alexander Veremyev added a comment - Done.
Hide
Wil Sinclair added a comment -

Updating for the 1.6.0 release.

Show
Wil Sinclair added a comment - Updating for the 1.6.0 release.

People

Vote (0)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: