Back to Blog
Developer guide
PHPMay 24, 2026

Common PHP Fatal Errors and How to Fix Them

PHP is a popular scripting language used for web development, but it's not immune to errors. Fatal errors can bring your application to a grinding halt, making it essential to understand what causes them and how to fix them. In this article, we'll cover common PHP fatal errors, their causes, and step-by-step solutions to get your application up and running again.

1. Fatal error: Uncaught Exception

A fatal error occurs when PHP encounters an uncaught exception, typically due to a programming mistake or a library issue.

Why It Happens

This error occurs when a PHP script throws an exception that's not caught by a try-catch block or a custom error handler.

How to Fix It

To fix this error, ensure that your PHP script has a try-catch block to catch any exceptions that might be thrown. You can also use a custom error handler to catch and handle exceptions.


2. Fatal error: Out of memory

A fatal error occurs when PHP runs out of memory, typically due to a memory leak or an excessively large dataset.

Why It Happens

This error occurs when PHP's memory limit is exceeded, causing it to terminate the script.

How to Fix It

To fix this error, increase the memory limit in your PHP configuration or use efficient memory management techniques, such as using arrays instead of objects or using caching mechanisms.


3. Fatal error: Allowed memory size of X bytes exhausted

A fatal error occurs when PHP exhausts its memory limit, typically due to a memory leak or an excessively large dataset.

Why It Happens

This error occurs when PHP's memory limit is exceeded, causing it to terminate the script.

How to Fix It

To fix this error, increase the memory limit in your PHP configuration or use efficient memory management techniques, such as using arrays instead of objects or using caching mechanisms.


4. Fatal error: Call to undefined function

A fatal error occurs when PHP encounters a function that's not defined, typically due to a missing library or a typo in the function name.

Why It Happens

This error occurs when PHP encounters a function that's not defined in the current scope or hasn't been loaded by a library.

How to Fix It

To fix this error, ensure that the required library or function is loaded and available in the current scope. You can use the get_declared_classes function to list all declared classes and functions.


5. Fatal error: Cannot redeclare class

A fatal error occurs when PHP encounters a class that's already been declared, typically due to a duplicate class definition or a missing namespace.

Why It Happens

This error occurs when PHP encounters a class that's already been declared in the current scope or hasn't been loaded by a library.

How to Fix It

To fix this error, ensure that the class is declared only once and in the correct scope. You can also use the get_declared_classes function to list all declared classes and functions.


6. Fatal error: Cannot redeclare function

A fatal error occurs when PHP encounters a function that's already been declared, typically due to a duplicate function definition or a missing namespace.

Why It Happens

This error occurs when PHP encounters a function that's already been declared in the current scope or hasn't been loaded by a library.

How to Fix It

To fix this error, ensure that the function is declared only once and in the correct scope. You can also use the get_declared_functions function to list all declared functions.


7. Fatal error: Maximum execution time exceeded

A fatal error occurs when PHP exceeds the maximum execution time, typically due to a long-running query or an inefficient algorithm.

Why It Happens

This error occurs when PHP's maximum execution time is exceeded, causing it to terminate the script.

How to Fix It

To fix this error, increase the maximum execution time in your PHP configuration or optimize your code to reduce execution time.

Conclusion

PHP fatal errors can bring your application to a halt, but understanding what causes them and how to fix them is essential to ensure smooth application performance. By following the step-by-step solutions outlined in this article, you can identify and fix common PHP fatal errors and get your application back up and running again.

Explore More Debugging Resources

- [Browse all PHP errors](/languages/php)

- [Browse errors by type](/error-types)

- [Search all documented errors](/search)

- [Use the Error Explainer](/error-explainer-tool)

Browse allPhp errors

Related PHP Articles

Have a specific error? Get an instant explanation.

Explain an Error