ZF-3196: E_WARNING is thrown (and no exception) when parse_ini_file fails in Zend_Config_Ini

Issue Type: Bug Created: 2008-05-05T05:53:16.000+0000 Last Updated: 2008-09-02T10:39:44.000+0000 Status: Resolved Fix version(s): - 1.6.0 (02/Sep/08)

Reporter: Shahar Evron (shahar) Assignee: Rob Allen (rob) Tags: - Zend_Config

Related issues: Attachments:


When there is a problem parsing the ini file passed to Zend_Config_Ini constructor, the PHP warning message is not caught and no exception is thrown. This is problematic because the developer has no way of knowing that a problem has happened - plus the E_WARNING message should not be displayed.

Use the following ini file to reproduce:

<pre class="highlight">
foo = ("bar")

Then, try to load this file with Zend_Config_Ini

Expected result: An exception thrown


Posted by julien PAULI (doctorrock83) on 2008-05-05T10:34:43.000+0000

I cannot reproduce your use-cased bug with PHP 5.2.5 and ZF at r9372

However, there is a PHP warning if the file loaded cannot be found or is not readable You can find more info in #ZF-2207

Posted by Rob Allen (rob) on 2008-06-08T08:06:23.000+0000

For PHP 5.2.0 or higher we can use error_get_last() to find the warning. e.g:

<pre class="highlight">
        $iniArray = @parse_ini_file($filename, true); // convert any warnings into exceptions
        $lastError = error_get_last();
        if($lastError && $lastError['line'] = (__LINE__-2) && strstr($lastError['file'], 'Ini.php')) {
             * @see Zend_Config_Exception
            require_once 'Zend/Config/Exception.php';
            throw new Zend_Config_Exception($lastError['message']);

As we need to support PHP 5.1.4, we have to use a custom error handler:

<pre class="highlight">
        $old_error_handler = set_error_handler(array('Zend_Config_Ini', 'parseIniFileErrorHandler'));
        $iniArray = parse_ini_file($filename, true); // convert any warnings into exceptions

Posted by Rob Allen (rob) on 2008-06-08T08:06:58.000+0000

Fixed on trunk in svn r9636.

Note that this introduces a small BC break if anyone was using the code with display_errors off, as now an exception will happen if this error occurs. Fixed only on trunk as a result.

Posted by julien PAULI (doctorrock83) on 2008-06-08T08:51:26.000+0000

You could use the track_errors cheat as well :

<pre class="highlight">
if (ini_get('track_errors') == 0) {
if(isset($php_errormsg)) {
    throw new exception($php_errormsg);

Posted by Wil Sinclair (wil) on 2008-09-02T10:39:44.000+0000

Updating for the 1.6.0 release.

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.