Home » Website Errors » PHP Parse Error or Fatal Error: Read the Message and Fix the Line
PHP Parse Error or Fatal Error: Read the Message and Fix the Line
PHP errors look alarming, but they are among the most honest errors on the web. A typical one reads:
PHP Parse error: syntax error, unexpected token "}", expecting ";" in /home/site/public_html/wp-content/themes/mytheme/functions.php on line 48
It names the problem, the file and the line. Your job is to get to that file, look in the right place, and fix it safely.
Parse errors vs. fatal errors
| Type | When it happens | Typical cause |
|---|---|---|
| Parse error | Before any code runs. PHP cannot read the file. | Typo: missing ;, unmatched { or (, stray quote |
| Fatal error | While the code runs. | Undefined function, missing class, out of memory, wrong argument type |
| Warning / Notice | While running, but execution continues | Usually not what breaks the page |
A parse error in a file that loads on every request (a theme's functions.php, a config file) takes the whole site down. A fatal error may only break the pages that run that code.
Step 1: get the full message
If you only see a blank page or "There has been a critical error on this website", the message is hidden. Find it in:
- The host's error log (control panel, or
error_logfiles in site folders). - WordPress's debug log: add to
wp-config.phpabove "That's all, stop editing":
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
Reload the page, then read wp-content/debug.log.
- WordPress also emails the admin address with a recovery link for many fatal errors. Check that inbox.
Step 2: open the file and look above the line
Open the named file in a code editor with line numbers (VS Code, Notepad++, or the host's code editor). Go to the line, then read the few lines before it. Look for:
- A line that should end with
;but does not. - An opening
{,(or[with no partner. Good editors highlight matching pairs. - A string that opens with
'and closes with", or contains an unescaped'(as in'Don't'). - Code pasted from a website with curly quotes (
’or“) instead of straight ones. - A stray
<?phpinside a file that is already in PHP mode.
Step 3: if you did not write the code
Most PHP errors on small sites come from code someone else wrote:
- A plugin or theme update: roll back to the previous version, or disable the plugin by renaming its folder in
wp-content/plugins/. - A snippet pasted into
functions.php: remove the snippet you added. Better, keep custom snippets in a small plugin such as Code Snippets, which catches errors before saving. - A PHP version change: old code may use functions removed in PHP 8 (like
create_functionoreach). Switch back to the previous PHP version in the control panel as a short-term fix, then update the code.
Step 4: check your fix before uploading
Run PHP's built-in syntax check locally or over SSH:
php -l functions.php
It prints No syntax errors detected or the exact problem. This takes a second and prevents a second outage.
Common mistakes
- Editing live theme files in the WordPress editor, where one typo locks you out.
- Looking only at the reported line instead of the lines above it.
- Copying code from a blog post with typographic quotes.
- Leaving
WP_DEBUG_DISPLAYset to true, which prints errors to visitors.
Frequently Asked Questions
The error points to a line that looks fine. Why?
PHP reports where it gave up, not where the mistake started. A missing semicolon, bracket or quote on an earlier line only becomes a problem when PHP reaches the next statement. Check the lines just above.
Can I fix it if I am locked out of the WordPress dashboard?
Yes. Edit or replace the broken file over FTP or the hosting file manager. If a plugin caused it, renaming that plugin's folder disables it and brings the dashboard back.
What does 'Call to undefined function' mean?
The code uses a function that does not exist in this environment, usually because a plugin it depends on is inactive, a PHP extension is missing, or the function was removed in a newer PHP version.
Found a mistake or still stuck? Contact us. See how we write and check these guides in our editorial policy, or read about DocumentGuy.