# Common PHP errors and how to fix them

> What PHP errors like "unexpected T_STRING", "Cannot redeclare", "Call to undefined function" and "headers already sent" mean, and how to fix them.

Source: https://helpcenter.ruachost.com/developers/php/common-php-errors/

First, find the full error message. It's in the `error_log` file in your website's folder, or in `wp-content/debug.log` for WordPress. See [Finding PHP error logs](https://helpcenter.ruachost.com/developers/php/enabling-php-error-logging/). The message names the **file** and **line number** where PHP found the problem.

## Parse error: syntax error, unexpected …

```
PHP Parse error: syntax error, unexpected identifier "echo" in /home/cpuser/public_html/functions.php on line 25
```

Older PHP versions say `unexpected T_STRING`, `unexpected T_VARIABLE` or `unexpected end of file`. They all mean the code isn't written correctly, so PHP can't read it. Usually it's a small typo **on that line or the line just before it**:

- a missing semicolon `;` at the end of the previous line
- a missing or extra quote `'` or `"`, bracket `)` or brace `}`
- a curly quote (`’` or `“`) pasted from a word processor or website, instead of a straight quote

`unexpected end of file` usually means a `{` was never closed.

**To fix it:** open the file in File Manager's code editor, go to the line number, and check that line and the one above it. If you just edited the file, undo your change. If the file belongs to a plugin or theme you didn't edit, reinstall or update it.

## Fatal error: Cannot redeclare …

```
PHP Fatal error: Cannot redeclare my_function() (previously declared in /home/cpuser/public_html/wp-content/themes/mytheme/functions.php:10)
```

The same function is defined twice. Common causes:

- the same code was pasted twice into `functions.php` or another file
- two plugins, or a plugin and your theme, include the same code
- a file is loaded with `include` or `require` more than once

**To fix it:** remove the duplicate function, or turn off one of the two plugins. In your own code, use `require_once` instead of `require`, or wrap the function in `if ( ! function_exists( 'my_function' ) ) { … }`.

## Fatal error: Call to undefined function …

```
PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen()
```

Either the function's PHP extension is turned off, or the function was removed from your PHP version.

| Function starts with | Turn on this extension |
| --- | --- |
| `mb_` | `mbstring` |
| `imagecreate`, `imagejpeg`, `getimagesize` | `gd` |
| `curl_` | `curl` |
| `mysqli_` | `mysqli` (or `nd_mysqli`) |
| `zip_`, `ZipArchive` | `zip` |
| `intl`, `Normalizer`, `NumberFormatter` | `intl` |
| `simplexml_`, `dom` | `simplexml`, `dom` |
| `sodium_` | `sodium` |

Turn extensions on in cPanel under **Select PHP Version → Extensions**. See [Changing your PHP version and settings](https://helpcenter.ruachost.com/cpanel/software/changing-php-versions-and-settings-using-php-selector/).

If the function is `mysql_connect()`, `each()`, `create_function()` or `ereg()`, it was **removed** in PHP 7 or 8. Update the script, or as a short-term fix switch to an older PHP version.

## Allowed memory size exhausted

A script used more memory than `memory_limit` allows. See [PHP memory limit vs your plan's RAM](https://helpcenter.ruachost.com/developers/php/resolving-the-allowed-memory-size-exhausted-php-error-message/).

## Maximum execution time of 60 seconds exceeded

A script ran longer than `max_execution_time`. Raise it in **Select PHP Version → Options** (for example to 300), or run long jobs such as imports and backups as a [cron job](https://helpcenter.ruachost.com/developers/php/running-php-scripts-from-cron-jobs/).

## Warning: Cannot modify header information – headers already sent

```
PHP Warning: Cannot modify header information - headers already sent by (output started at /home/cpuser/public_html/wp-config.php:1)
```

Something was sent to the browser before the page header, often a **blank line or space before `<?php`**, or after a closing `?>`. Open the file named after **output started at**, and remove any spaces or empty lines before `<?php` at the top and after `?>` at the end. Saving the file as "UTF-8 without BOM" also helps.

## Uncaught Error: Class "…" not found

A PHP class can't be found. Usually a file is missing, Composer packages weren't installed (`vendor` folder missing), or a PHP extension is off. Re-upload the app's files, run `composer install`, or check the extension list above.

## Deprecated: … and Warning: …

These aren't errors that stop your site. **Deprecated** means the code will stop working in a future PHP version; **Warning** means something unexpected happened but the script carried on. Update the plugin, theme or script that's named. They're logged, not shown to visitors, unless `display_errors` is On.

## Errors after changing PHP version

If errors started right after you changed your PHP version, switch back to the previous version in **Select PHP Version**, then update your software before trying again. See [Resolving common PHP upgrade issues](https://helpcenter.ruachost.com/developers/php/resolving-common-php-upgrade-issues/).

Still stuck? [Open a support ticket](https://dashboard.ruachost.com/submitticket.php) with the full error message and the page's address.
