Back to Blog
Developer guide
PHPMay 2, 2026

PHP Runtime Errors Every Developer Should Know

PHP runtime errors can be frustrating and time-consuming to resolve, especially when you're under a tight deadline. As a PHP developer, it's essential to be aware of the most common runtime errors, their causes, and solutions to avoid wasting time and improve your development skills. In this article, we'll cover the most critical PHP runtime errors and provide actionable advice on how to fix them. By the end of this article, you'll be equipped with the knowledge and skills to tackle even the most challenging PHP runtime errors.

1. Fatal Error: Maximum Execution Time Exceeded

The Fatal Error: Maximum Execution Time Exceeded error occurs when a PHP script takes longer than the maximum execution time allowed by the PHP configuration

Why It Happens

This error is usually caused by a script that runs for an extended period, such as a recursive function or a loop that doesn't have a proper exit condition

How to Fix It

To fix this error, you can increase the maximum execution time by editing the php.ini file or using the set_time_limit() function in your PHP script


2. Fatal Error: Allowed Memory Size of xxx bytes Exhausted

The Fatal Error: Allowed Memory Size of xxx bytes Exhausted error occurs when a PHP script exceeds the allowed memory size

Why It Happens

This error is usually caused by a script that uses excessive memory, such as a large array or a complex data structure

How to Fix It

To fix this error, you can increase the memory limit by editing the php.ini file or using the memory_limit directive in your PHP script


3. Warning: Invalid argument supplied for foreach()

The Warning: Invalid argument supplied for foreach() error occurs when a foreach loop encounters an invalid or non-array argument

Why It Happens

This error is usually caused by a variable that is not an array or is an empty array

How to Fix It

To fix this error, you can check the type and value of the variable before passing it to the foreach loop, and ensure that it's an array or a valid argument


4. Warning: Division by zero

The Warning: Division by zero error occurs when a division operation encounters a zero divisor

Why It Happens

This error is usually caused by a variable that is zero or null

How to Fix It

To fix this error, you can check the value of the variable before performing the division operation, and handle the case where the divisor is zero


5. Fatal Error: Cannot redeclare class

The Fatal Error: Cannot redeclare class error occurs when a class is declared multiple times in a script

Why It Happens

This error is usually caused by a script that includes multiple files that declare the same class

How to Fix It

To fix this error, you can remove duplicate class declarations by using the include_once() or require_once() functions, or by using an autoloader


6. Fatal Error: Cannot redeclare function

The Fatal Error: Cannot redeclare function error occurs when a function is declared multiple times in a script

Why It Happens

This error is usually caused by a script that includes multiple files that declare the same function

How to Fix It

To fix this error, you can remove duplicate function declarations by using the include_once() or require_once() functions, or by using a function autoloader


7. Warning: Cannot modify header information - headers already sent

The Warning: Cannot modify header information - headers already sent error occurs when a script tries to modify header information after output has already been sent

Why It Happens

This error is usually caused by a script that outputs content before sending header information

How to Fix It

To fix this error, you can remove any output before sending header information, or use the output buffering functions to delay output until after header information has been sent

Conclusion

PHP runtime errors can be frustrating and time-consuming to resolve, but by understanding the causes and solutions outlined in this article, you'll be better equipped to tackle even the most challenging errors. Remember to always check the type and value of variables, handle exceptions, and use output buffering functions to avoid common errors. With practice and experience, you'll become more proficient in debugging and resolving PHP runtime errors, and your code will become more reliable and maintainable.

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