---
title: "How To Catch PHP Fatal Error In CodeIgniter"
url: https://thecancerus.com/how-to-catch-php-fatal-error-in-codeigniter/
date: 2011-01-01
modified: 2011-01-01
author: "ican"
description: "My last few blog post’s are result of the project that I am currently working on, and this blog is also in that series. We needed to catch PHP Fatal..."
categories:
  - "how too?"
tags:
  - "codeigniter"
  - "php"
  - "php fatal errors"
word_count: 166
---

# How To Catch PHP Fatal Error In CodeIgniter

My [last](http://thecancerus.com/simple-way-to-add-global-exception-handling-in-codeigniter/) [few](http://thecancerus.com/installing-pear-and-phpunit-on-wamp-and-windows-7/) [blog](http://thecancerus.com/testing-extjs-application-with-selenium-few-pointers/) post’s are result of the project that I am currently working on, and this blog is also in that series.

We needed to catch PHP Fatal Errors in the production environment and notify about it to developers, also at the same time, showing our beautiful fail whale page to user instead of ugly error or a white screen of death.

Here I will show you how to do this in CodeIgniter, though credit for this idea goes to [hipertracker](http://stackoverflow.com/questions/277224/how-do-i-catch-a-php-fatal-error/3795403#3795403).

First of all you will need to setup a hook, so update your *hooks.php* file with following code
$hook['pre_system'][] = array(
'class' => 'PHPFatalError',
'function' => 'setHandler',
'filename' => 'PHPFatalError.php',
'filepath' => 'hooks'
);
Now put the code shown below in *PHPFatalError.php* file in your applications *hooks* folder.

This is the simplifed version of what I have done, so please update *handleShutdown *function* *as per your needs.

Check out PHPCamp a place to share news, views and articles that are useful to [PHP community](http://phpcamp.net/?utm_medium=blog_post&utm_source=amiworks_co_in&utm_campaign=phpunit_win7).