Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I turn on the PHP error reporting in Zend Framework 2?

Everytime I receive an error in Zend Framework 2, I get just 500 Internal Server Error displayed and have to search through the Zend Server error log. I've tried putting this to my config/autoload/local.php file but it doesn't work:

return array(
    'phpSettings' => array(
        'display_startup_errors' => true,
        'display_errors' => true,
        ),
);
like image 617
Magda K. Avatar asked Mar 10 '13 10:03

Magda K.


2 Answers

There is no native support for that in zf2 (afaik). You'd either have to set them in php.ini itself, or set them in index.php

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);

If you really want to be able to supply them as config settings, you could keep what you have and do that in a module bootstrap, get them from config, and call ini_set() on each key value pair

public function onBootstrap(EventInterface $e) {
    $app = $e->getApplication();
    $sm = $app->getServiceManager();
    $config = $sm->get('Config');
    $phpSettings = isset($config['phpSettings']) ? $config['phpSettings'] : array();
    if(!empty($phpSettings)) {
        foreach($phpSettings as $key => $value) {
            ini_set($key, $value);
        }
    }
}

Edit: as @akond rightly points out in the comments, you could just add the ini_set lines to local.php which is a better solution.

like image 181
Crisp Avatar answered Oct 29 '22 10:10

Crisp


To easilly configure phpSettings on your ZF2 app, you should consider using DluPhpSettings.

With this module, you can configure your settings for each environment you have:

/* Local application configuration in /config/autoload/phpsettings.local.php */
<?php
return array(
    'phpSettings'   => array(
        'display_startup_errors'        => false,
        'display_errors'                => false,
        'max_execution_time'            => 60,
        'date.timezone'                 => 'Europe/Prague',
        'mbstring.internal_encoding'    => 'UTF-8',
    ),
);

Look this blog post for more info too!

like image 37
Vinicius Garcia Avatar answered Oct 29 '22 11:10

Vinicius Garcia